Skip to content

Commit

Permalink
Reformat line length to 120
Browse files Browse the repository at this point in the history
  • Loading branch information
SukramJ committed Dec 21, 2024
1 parent a1eb241 commit 3523258
Show file tree
Hide file tree
Showing 34 changed files with 361 additions and 826 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ repos:
- id: python-typing-update
stages: [manual]
args:
- --py311-plus
- --py312-plus
- --force
- --keep-updates
files: ^(tests|script)/.+\.py$
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Add advanced config options to define markers for programs and sysvars.
This means that not all programs/sysvars are retrieved except the internal ones.
- Move periodic checks for device firmware updates to lib
- Reformat line length to 120

# Version 1.75.1 (2024-12-15)

Expand Down
36 changes: 8 additions & 28 deletions custom_components/homematicip_local/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@

from awesomeversion import AwesomeVersion
from hahomematic import __version__ as HAHM_VERSION
from hahomematic.const import (
DEFAULT_ENABLE_SYSVAR_SCAN,
DEFAULT_SYS_SCAN_INTERVAL,
DEFAULT_UN_IGNORES,
)
from hahomematic.const import DEFAULT_ENABLE_SYSVAR_SCAN, DEFAULT_SYS_SCAN_INTERVAL, DEFAULT_UN_IGNORES
from hahomematic.support import cleanup_cache_dirs, find_free_port

from homeassistant.config_entries import ConfigEntry
Expand Down Expand Up @@ -111,30 +107,22 @@ async def async_unload_entry(hass: HomeAssistant, entry: HomematicConfigEntry) -

async def async_remove_entry(hass: HomeAssistant, entry: HomematicConfigEntry) -> None:
"""Handle removal of an entry."""
cleanup_cache_dirs(
instance_name=entry.data["instance_name"], storage_folder=get_storage_folder(hass=hass)
)
cleanup_cache_dirs(instance_name=entry.data["instance_name"], storage_folder=get_storage_folder(hass=hass))


async def async_remove_config_entry_device(
hass: HomeAssistant, entry: HomematicConfigEntry, device_entry: dr.DeviceEntry
) -> bool:
"""Remove a config entry from a device."""

if (
address_data := get_device_address_at_interface_from_identifiers(
identifiers=device_entry.identifiers
)
) is None:
if (address_data := get_device_address_at_interface_from_identifiers(identifiers=device_entry.identifiers)) is None:
return False

interface_id: str = address_data[0]
device_address: str = address_data[1]

if interface_id and device_address and (control_unit := entry.runtime_data):
await control_unit.central.delete_device(
interface_id=interface_id, device_address=device_address
)
await control_unit.central.delete_device(interface_id=interface_id, device_address=device_address)
_LOGGER.debug(
"Called delete_device: %s, %s",
interface_id,
Expand Down Expand Up @@ -194,9 +182,7 @@ def update_entity_unique_id(entity_entry: er.RegistryEntry) -> dict[str, str] |
CONF_ENABLE_SYSTEM_NOTIFICATIONS: DEFAULT_ENABLE_SYSTEM_NOTIFICATIONS,
CONF_UN_IGNORES: DEFAULT_UN_IGNORES,
}
data[CONF_ADVANCED_CONFIG] = (
{} if advanced_config == default_advanced_config else advanced_config
)
data[CONF_ADVANCED_CONFIG] = {} if advanced_config == default_advanced_config else advanced_config

def del_param(name: str) -> None:
with contextlib.suppress(Exception):
Expand All @@ -207,22 +193,16 @@ def del_param(name: str) -> None:
del_param(name=CONF_ENABLE_SYSTEM_NOTIFICATIONS)
del_param(name=CONF_UN_IGNORES)

cleanup_cache_dirs(
instance_name=entry.data["instance_name"], storage_folder=get_storage_folder(hass=hass)
)
cleanup_cache_dirs(instance_name=entry.data["instance_name"], storage_folder=get_storage_folder(hass=hass))
hass.config_entries.async_update_entry(entry, version=5, data=data)
if entry.version == 5:
data = dict(entry.data)
cleanup_cache_dirs(
instance_name=entry.data["instance_name"], storage_folder=get_storage_folder(hass=hass)
)
cleanup_cache_dirs(instance_name=entry.data["instance_name"], storage_folder=get_storage_folder(hass=hass))
hass.config_entries.async_update_entry(entry, version=6, data=data)
if entry.version == 6:
data = dict(entry.data)
if data.get(CONF_ADVANCED_CONFIG):
data[CONF_ADVANCED_CONFIG][CONF_ENABLE_PROGRAM_SCAN] = data[CONF_ADVANCED_CONFIG][
CONF_ENABLE_SYSVAR_SCAN
]
data[CONF_ADVANCED_CONFIG][CONF_ENABLE_PROGRAM_SCAN] = data[CONF_ADVANCED_CONFIG][CONF_ENABLE_SYSVAR_SCAN]
hass.config_entries.async_update_entry(entry, version=7, data=data)
_LOGGER.info("Migration to version %s successful", entry.version)
return True
22 changes: 6 additions & 16 deletions custom_components/homematicip_local/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def async_add_binary_sensor(data_points: tuple[DpBinarySensor, ...]) -> None:
"""Add binary_sensor from Homematic(IP) Local."""
_LOGGER.debug("ASYNC_ADD_BINARY_SENSOR: Adding %i data points", len(data_points))
if entities := [
HaHomematicBinarySensor(control_unit=control_unit, data_point=data_point)
for data_point in data_points
HaHomematicBinarySensor(control_unit=control_unit, data_point=data_point) for data_point in data_points
]:
async_add_entities(entities)

Expand All @@ -52,9 +51,7 @@ def async_add_hub_binary_sensor(data_points: tuple[SysvarDpBinarySensor, ...]) -
entry.async_on_unload(
func=async_dispatcher_connect(
hass=hass,
signal=signal_new_data_point(
entry_id=entry.entry_id, platform=DataPointCategory.BINARY_SENSOR
),
signal=signal_new_data_point(entry_id=entry.entry_id, platform=DataPointCategory.BINARY_SENSOR),
target=async_add_binary_sensor,
)
)
Expand All @@ -66,13 +63,9 @@ def async_add_hub_binary_sensor(data_points: tuple[SysvarDpBinarySensor, ...]) -
)
)

async_add_binary_sensor(
data_points=control_unit.get_new_data_points(data_point_type=DpBinarySensor)
)
async_add_binary_sensor(data_points=control_unit.get_new_data_points(data_point_type=DpBinarySensor))

async_add_hub_binary_sensor(
data_points=control_unit.get_new_hub_data_points(data_point_type=SysvarDpBinarySensor)
)
async_add_hub_binary_sensor(data_points=control_unit.get_new_hub_data_points(data_point_type=SysvarDpBinarySensor))


class HaHomematicBinarySensor(HaHomematicGenericRestoreEntity[DpBinarySensor], BinarySensorEntity):
Expand All @@ -86,16 +79,13 @@ def is_on(self) -> bool | None:
if (
self.is_restored
and self._restored_state
and (restored_state := self._restored_state.state)
not in (STATE_UNKNOWN, STATE_UNAVAILABLE)
and (restored_state := self._restored_state.state) not in (STATE_UNKNOWN, STATE_UNAVAILABLE)
):
return restored_state == STATE_ON
return self._data_point.default # type: ignore[no-any-return]


class HaHomematicSysvarBinarySensor(
HaHomematicGenericSysvarEntity[SysvarDpBinarySensor], BinarySensorEntity
):
class HaHomematicSysvarBinarySensor(HaHomematicGenericSysvarEntity[SysvarDpBinarySensor], BinarySensorEntity):
"""Representation of the HomematicIP hub binary_sensor entity."""

@property
Expand Down
22 changes: 5 additions & 17 deletions custom_components/homematicip_local/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@

from . import HomematicConfigEntry
from .control_unit import ControlUnit, signal_new_data_point
from .generic_entity import (
ATTR_DESCRIPTION,
ATTR_NAME,
HaHomematicGenericEntity,
HaHomematicGenericHubEntity,
)
from .generic_entity import ATTR_DESCRIPTION, ATTR_NAME, HaHomematicGenericEntity, HaHomematicGenericHubEntity

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -53,36 +48,29 @@ def async_add_program_button(data_points: tuple[ProgramDpButton, ...]) -> None:
_LOGGER.debug("ASYNC_ADD_PROGRAM_BUTTON: Adding %i data points", len(data_points))

if entities := [
HaHomematicProgramButton(control_unit=control_unit, data_point=data_point)
for data_point in data_points
HaHomematicProgramButton(control_unit=control_unit, data_point=data_point) for data_point in data_points
]:
async_add_entities(entities)

entry.async_on_unload(
func=async_dispatcher_connect(
hass=hass,
signal=signal_new_data_point(
entry_id=entry.entry_id, platform=DataPointCategory.BUTTON
),
signal=signal_new_data_point(entry_id=entry.entry_id, platform=DataPointCategory.BUTTON),
target=async_add_button,
)
)

entry.async_on_unload(
func=async_dispatcher_connect(
hass=hass,
signal=signal_new_data_point(
entry_id=entry.entry_id, platform=DataPointCategory.HUB_BUTTON
),
signal=signal_new_data_point(entry_id=entry.entry_id, platform=DataPointCategory.HUB_BUTTON),
target=async_add_program_button,
)
)

async_add_button(data_points=control_unit.get_new_data_points(data_point_type=DpButton))

async_add_program_button(
data_points=control_unit.get_new_hub_data_points(data_point_type=ProgramDpButton)
)
async_add_program_button(data_points=control_unit.get_new_hub_data_points(data_point_type=ProgramDpButton))


class HaHomematicButton(HaHomematicGenericEntity[DpButton], ButtonEntity):
Expand Down
66 changes: 16 additions & 50 deletions custom_components/homematicip_local/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,12 @@ def async_add_climate(data_points: tuple[BaseCustomDpClimate, ...]) -> None:
entry.async_on_unload(
func=async_dispatcher_connect(
hass=hass,
signal=signal_new_data_point(
entry_id=entry.entry_id, platform=DataPointCategory.CLIMATE
),
signal=signal_new_data_point(entry_id=entry.entry_id, platform=DataPointCategory.CLIMATE),
target=async_add_climate,
)
)

async_add_climate(
data_points=control_unit.get_new_data_points(data_point_type=BaseCustomDpClimate)
)
async_add_climate(data_points=control_unit.get_new_data_points(data_point_type=BaseCustomDpClimate))

platform = entity_platform.async_get_current_platform()

Expand All @@ -135,19 +131,15 @@ def async_add_climate(data_points: tuple[BaseCustomDpClimate, ...]) -> None:
schema={
vol.Optional(ATTR_AWAY_START): cv.datetime,
vol.Required(ATTR_AWAY_END): cv.datetime,
vol.Required(ATTR_AWAY_TEMPERATURE, default=18.0): vol.All(
vol.Coerce(float), vol.Range(min=5.0, max=30.5)
),
vol.Required(ATTR_AWAY_TEMPERATURE, default=18.0): vol.All(vol.Coerce(float), vol.Range(min=5.0, max=30.5)),
},
func="async_enable_away_mode_by_calendar",
)
platform.async_register_entity_service(
name=HmipLocalServices.ENABLE_AWAY_MODE_BY_DURATION,
schema={
vol.Required(ATTR_AWAY_HOURS): cv.positive_int,
vol.Required(ATTR_AWAY_TEMPERATURE, default=18.0): vol.All(
vol.Coerce(float), vol.Range(min=5.0, max=30.5)
),
vol.Required(ATTR_AWAY_TEMPERATURE, default=18.0): vol.All(vol.Coerce(float), vol.Range(min=5.0, max=30.5)),
},
func="async_enable_away_mode_by_duration",
)
Expand Down Expand Up @@ -314,11 +306,7 @@ def hvac_mode(self) -> HVACMode | None:
@property
def hvac_modes(self) -> list[HVACMode]:
"""Return the list of available hvac modes."""
return [
HM_TO_HA_HVAC_MODE[mode]
for mode in self._data_point.modes
if mode in HM_TO_HA_HVAC_MODE
]
return [HM_TO_HA_HVAC_MODE[mode] for mode in self._data_point.modes if mode in HM_TO_HA_HVAC_MODE]

@property
def min_temp(self) -> float:
Expand Down Expand Up @@ -358,9 +346,7 @@ def preset_modes(self) -> list[str]:
def supported_features(self) -> ClimateEntityFeature:
"""Return the list of supported features."""
supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.TURN_OFF | ClimateEntityFeature.TURN_ON
)
if self._data_point.supports_profiles:
supported_features |= ClimateEntityFeature.PRESET_MODE
Expand Down Expand Up @@ -414,17 +400,11 @@ async def async_enable_away_mode_by_calendar(
) -> None:
"""Enable the away mode by calendar on thermostat."""
start = start or datetime.now() - timedelta(minutes=10)
await self._data_point.enable_away_mode_by_calendar(
start=start, end=end, away_temperature=away_temperature
)
await self._data_point.enable_away_mode_by_calendar(start=start, end=end, away_temperature=away_temperature)

async def async_enable_away_mode_by_duration(
self, hours: int, away_temperature: float
) -> None:
async def async_enable_away_mode_by_duration(self, hours: int, away_temperature: float) -> None:
"""Enable the away mode by duration on thermostat."""
await self._data_point.enable_away_mode_by_duration(
hours=hours, away_temperature=away_temperature
)
await self._data_point.enable_away_mode_by_duration(hours=hours, away_temperature=away_temperature)

async def async_disable_away_mode(self) -> None:
"""Disable the away mode on thermostat."""
Expand All @@ -434,13 +414,9 @@ async def async_copy_schedule(self, source_entity_id: str) -> None:
"""Copy a schedule from this entity to another."""
if source_climate_data_point := cast(
BaseCustomDpClimate,
self._data_point.device.central.get_data_point_by_custom_id(
custom_id=source_entity_id
),
self._data_point.device.central.get_data_point_by_custom_id(custom_id=source_entity_id),
):
await source_climate_data_point.copy_schedule(
target_climate_data_point=self._data_point
)
await source_climate_data_point.copy_schedule(target_climate_data_point=self._data_point)

async def async_copy_schedule_profile(
self, source_profile: str, target_profile: str, source_entity_id: str | None = None
Expand All @@ -449,9 +425,7 @@ async def async_copy_schedule_profile(
if source_entity_id and (
source_climate_data_point := cast(
BaseCustomDpClimate,
self._data_point.device.central.get_data_point_by_custom_id(
custom_id=source_entity_id
),
self._data_point.device.central.get_data_point_by_custom_id(custom_id=source_entity_id),
)
):
await source_climate_data_point.copy_schedule_profile(
Expand All @@ -460,17 +434,13 @@ async def async_copy_schedule_profile(
target_climate_data_point=self._data_point,
)
else:
await self._data_point.copy_schedule_profile(
source_profile=source_profile, target_profile=target_profile
)
await self._data_point.copy_schedule_profile(source_profile=source_profile, target_profile=target_profile)

async def async_get_schedule_profile(self, profile: str) -> ServiceResponse:
"""Return the schedule profile."""
return await self._data_point.get_schedule_profile(profile=profile) # type: ignore[no-any-return]

async def async_get_schedule_profile_weekday(
self, profile: str, weekday: str
) -> ServiceResponse:
async def async_get_schedule_profile_weekday(self, profile: str, weekday: str) -> ServiceResponse:
"""Return the schedule profile weekday."""
return await self._data_point.get_schedule_profile_weekday( # type: ignore[no-any-return]
profile=profile, weekday=weekday
Expand All @@ -492,14 +462,10 @@ async def async_set_schedule_simple_profile(
simple_profile_data=simple_profile_data,
)

async def async_set_schedule_profile_weekday(
self, profile: str, weekday: str, weekday_data: WEEKDAY_DICT
) -> None:
async def async_set_schedule_profile_weekday(self, profile: str, weekday: str, weekday_data: WEEKDAY_DICT) -> None:
"""Set the schedule profile weekday."""
weekday_data = {int(key): value for key, value in weekday_data.items()}
await self._data_point.set_schedule_profile_weekday(
profile=profile, weekday=weekday, weekday_data=weekday_data
)
await self._data_point.set_schedule_profile_weekday(profile=profile, weekday=weekday, weekday_data=weekday_data)

async def async_set_schedule_simple_profile_weekday(
self,
Expand Down
Loading

0 comments on commit 3523258

Please sign in to comment.