Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SukramJ committed Sep 30, 2024
1 parent 2dcac26 commit 7dcd3dc
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 114 deletions.
4 changes: 2 additions & 2 deletions hahomematic/central/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ def remove_event_subscription(self, entity: BaseParameterEntity) -> None:
async def execute_program(self, pid: str) -> bool:
"""Execute a program on CCU / Homegear."""
if client := self.primary_client:
return await client.execute_program(pid=pid)
return await client.execute_program(pid=pid) # type: ignore[no-any-return]
return False

async def fetch_sysvar_data(self, scheduled: bool) -> None:
Expand Down Expand Up @@ -1093,7 +1093,7 @@ async def set_install_mode(
self.name,
)
return False
return await self.get_client(interface_id=interface_id).set_install_mode(
return await self.get_client(interface_id=interface_id).set_install_mode( # type: ignore[no-any-return]
on=on, t=t, mode=mode, device_address=device_address
)

Expand Down
111 changes: 54 additions & 57 deletions hahomematic/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,27 +322,27 @@ async def check_connection_availability(self, handle_ping_pong: bool) -> bool:
"""Send ping to CCU to generate PONG event."""

@abstractmethod
@service
@service()
async def execute_program(self, pid: str) -> bool:
"""Execute a program on CCU / Homegear.."""

@abstractmethod
@service
@service()
async def set_system_variable(self, name: str, value: Any) -> bool:
"""Set a system variable on CCU / Homegear."""

@abstractmethod
@service
@service()
async def delete_system_variable(self, name: str) -> bool:
"""Delete a system variable from CCU / Homegear."""

@abstractmethod
@service
@service()
async def get_system_variable(self, name: str) -> str:
"""Get single system variable from CCU / Homegear."""

@abstractmethod
@service
@service()
async def get_all_system_variables(
self, include_internal: bool
) -> tuple[SystemVariableData, ...]:
Expand Down Expand Up @@ -394,7 +394,7 @@ async def get_device_description(self, device_address: str) -> tuple[DeviceDescr
)
return None

@service
@service()
async def set_install_mode(
self,
on: bool = True,
Expand All @@ -414,31 +414,28 @@ async def set_install_mode(

await self._proxy.setInstallMode(*args)
except BaseHomematicException as ex:
message = f"SET_INSTALL_MODE failed: {reduce_args(args=ex.args)}"
_LOGGER.warning(message)
raise ClientException(message) from ex
raise ClientException(f"SET_INSTALL_MODE failed: {reduce_args(args=ex.args)}") from ex
return True

@service
@service()
async def get_install_mode(self) -> int:
"""Get remaining time in seconds install mode is active from CCU / Homegear."""
try:
return await self._proxy.getInstallMode() # type: ignore[no-any-return]
except BaseHomematicException as ex:
message = f"GET_INSTALL_MODE failed: {reduce_args(args=ex.args)}"
_LOGGER.warning(message)
raise ClientException(message) from ex
raise ClientException(f"GET_INSTALL_MODE failed: {reduce_args(args=ex.args)}") from ex

@service
@service()
async def get_link_peers(self, address: str) -> tuple[str, ...] | None:
"""Return a list of link pers."""
try:
return tuple(await self._proxy.getLinkPeers(address))
except BaseHomematicException as ex:
message = f"GET_LINK_PEERS failed with for: {address}: {reduce_args(args=ex.args)}"
_LOGGER.warning(message)
raise ClientException(message) from ex
raise ClientException(
f"GET_LINK_PEERS failed with for: {address}: {reduce_args(args=ex.args)}"
) from ex

@service(level=logging.DEBUG)
async def get_value(
self,
channel_address: str,
Expand Down Expand Up @@ -467,6 +464,7 @@ async def get_value(
) from ex

@measure_execution_time
@service()
async def _set_value(
self,
channel_address: str,
Expand Down Expand Up @@ -513,9 +511,9 @@ async def _set_value(
)
return entity_keys # noqa: TRY300
except BaseHomematicException as ex:
message = f"SET_VALUE failed for {channel_address}/{parameter}/{value}: {reduce_args(args=ex.args)}"
_LOGGER.warning(message)
raise ClientException(message) from ex
raise ClientException(
f"SET_VALUE failed for {channel_address}/{parameter}/{value}: {reduce_args(args=ex.args)}"
) from ex

def _check_set_value(
self, channel_address: str, paramset_key: ParamsetKey, parameter: str, value: Any
Expand All @@ -529,7 +527,6 @@ def _check_set_value(
operation=Operations.WRITE,
)

@service
async def set_value(
self,
channel_address: str,
Expand All @@ -542,15 +539,15 @@ async def set_value(
) -> set[ENTITY_KEY]:
"""Set single value on paramset VALUES."""
if paramset_key == ParamsetKey.VALUES:
return await self._set_value(
return await self._set_value( # type: ignore[no-any-return]
channel_address=channel_address,
parameter=parameter,
value=value,
wait_for_callback=wait_for_callback,
rx_mode=rx_mode,
check_against_pd=check_against_pd,
)
return await self.put_paramset(
return await self.put_paramset( # type: ignore[no-any-return]
channel_address=channel_address,
paramset_key=paramset_key,
values={parameter: value},
Expand All @@ -559,7 +556,7 @@ async def set_value(
check_against_pd=check_against_pd,
)

@service
@service()
async def get_paramset(self, address: str, paramset_key: ParamsetKey | str) -> dict[str, Any]:
"""
Return a paramset from CCU.
Expand All @@ -575,12 +572,12 @@ async def get_paramset(self, address: str, paramset_key: ParamsetKey | str) -> d
)
return await self._proxy_read.getParamset(address, paramset_key) # type: ignore[no-any-return]
except BaseHomematicException as ex:
message = f"GET_PARAMSET failed with for {address}/{paramset_key}: {reduce_args(args=ex.args)}"
_LOGGER.warning(message)
raise ClientException(message) from ex
raise ClientException(
f"GET_PARAMSET failed with for {address}/{paramset_key}: {reduce_args(args=ex.args)}"
) from ex

@measure_execution_time
@service
@service()
async def put_paramset(
self,
channel_address: str,
Expand Down Expand Up @@ -655,9 +652,9 @@ async def put_paramset(
)
return entity_keys # noqa: TRY300
except BaseHomematicException as ex:
message = f"PUT_PARAMSET failed for {channel_address}/{paramset_key}/{values}: {reduce_args(args=ex.args)}"
_LOGGER.warning(message)
raise ClientException(message) from ex
raise ClientException(
f"PUT_PARAMSET failed for {channel_address}/{paramset_key}/{values}: {reduce_args(args=ex.args)}"
) from ex

def _check_put_paramset(
self, channel_address: str, paramset_key: ParamsetKey, values: dict[str, Any]
Expand Down Expand Up @@ -782,7 +779,7 @@ async def get_all_paramset_descriptions(
)
return all_paramsets

@service
@service()
async def update_device_firmware(self, device_address: str) -> bool:
"""Update the firmware of a homematic device."""
if device := self.central.get_device(address=device_address):
Expand All @@ -807,9 +804,9 @@ async def update_device_firmware(self, device_address: str) -> bool:
"success" if result else "failed",
)
except BaseHomematicException as ex:
message = f"UPDATE_DEVICE_FIRMWARE failed]: {reduce_args(args=ex.args)}"
_LOGGER.warning(message)
raise ClientException(message) from ex
raise ClientException(
f"UPDATE_DEVICE_FIRMWARE failed]: {reduce_args(args=ex.args)}"
) from ex
return result
return False

Expand Down Expand Up @@ -924,28 +921,28 @@ async def check_connection_availability(self, handle_ping_pong: bool) -> bool:
self.modified_at = INIT_DATETIME
return False

@service
@service()
async def execute_program(self, pid: str) -> bool:
"""Execute a program on CCU."""
return await self._json_rpc_client.execute_program(pid=pid)

@measure_execution_time
@service
@service()
async def set_system_variable(self, name: str, value: Any) -> bool:
"""Set a system variable on CCU / Homegear."""
return await self._json_rpc_client.set_system_variable(name=name, value=value)

@service
@service()
async def delete_system_variable(self, name: str) -> bool:
"""Delete a system variable from CCU / Homegear."""
return await self._json_rpc_client.delete_system_variable(name=name)

@service
@service()
async def get_system_variable(self, name: str) -> Any:
"""Get single system variable from CCU / Homegear."""
return await self._json_rpc_client.get_system_variable(name=name)

@service
@service()
async def get_all_system_variables(
self, include_internal: bool
) -> tuple[SystemVariableData, ...]:
Expand Down Expand Up @@ -1045,45 +1042,45 @@ async def check_connection_availability(self, handle_ping_pong: bool) -> bool:
self.modified_at = INIT_DATETIME
return False

@service
@service()
async def execute_program(self, pid: str) -> bool:
"""Execute a program on Homegear."""
return True

@measure_execution_time
@service
@service()
async def set_system_variable(self, name: str, value: Any) -> bool:
"""Set a system variable on CCU / Homegear."""
try:
await self._proxy.setSystemVariable(name, value)
except BaseHomematicException as ex:
message = f"SET_SYSTEM_VARIABLE failed: {reduce_args(args=ex.args)}"
_LOGGER.warning(message)
raise ClientException(message) from ex
raise ClientException(
f"SET_SYSTEM_VARIABLE failed: {reduce_args(args=ex.args)}"
) from ex
return True

@service
@service()
async def delete_system_variable(self, name: str) -> bool:
"""Delete a system variable from CCU / Homegear."""
try:
await self._proxy.deleteSystemVariable(name)
except BaseHomematicException as ex:
message = f"DELETE_SYSTEM_VARIABLE failed: {reduce_args(args=ex.args)}"
_LOGGER.warning(message)
raise ClientException(message) from ex
raise ClientException(
f"DELETE_SYSTEM_VARIABLE failed: {reduce_args(args=ex.args)}"
) from ex
return True

@service
@service()
async def get_system_variable(self, name: str) -> Any:
"""Get single system variable from CCU / Homegear."""
try:
return await self._proxy.getSystemVariable(name)
except BaseHomematicException as ex:
message = f"GET_SYSTEM_VARIABLE failed: {reduce_args(args=ex.args)}"
_LOGGER.warning(message)
raise ClientException(message) from ex
raise ClientException(
f"GET_SYSTEM_VARIABLE failed: {reduce_args(args=ex.args)}"
) from ex

@service
@service()
async def get_all_system_variables(
self, include_internal: bool
) -> tuple[SystemVariableData, ...]:
Expand All @@ -1094,9 +1091,9 @@ async def get_all_system_variables(
for name, value in hg_variables.items():
variables.append(SystemVariableData(name=name, value=value))
except BaseHomematicException as ex:
message = f"GET_ALL_SYSTEM_VARIABLES failed: {reduce_args(args=ex.args)}"
_LOGGER.warning(message)
raise ClientException(message) from ex
raise ClientException(
f"GET_ALL_SYSTEM_VARIABLES failed: {reduce_args(args=ex.args)}"
) from ex
return tuple(variables)

async def get_all_programs(self, include_internal: bool) -> tuple[ProgramData, ...]:
Expand Down
18 changes: 9 additions & 9 deletions hahomematic/platforms/custom/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,17 @@ async def set_preset_mode(
) -> None:
"""Set new preset mode."""

@service
@service()
async def enable_away_mode_by_calendar(
self, start: datetime, end: datetime, away_temperature: float
) -> None:
"""Enable the away mode by calendar on thermostat."""

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

@service
@service()
async def disable_away_mode(self) -> None:
"""Disable the away mode on thermostat."""

Expand Down Expand Up @@ -373,7 +373,7 @@ async def set_preset_mode(
elif preset_mode == PresetMode.ECO:
await self._e_lowering_mode.send_value(value=True, collector=collector)

@service
@service()
async def enable_away_mode_by_calendar(
self, start: datetime, end: datetime, away_temperature: float
) -> None:
Expand All @@ -385,7 +385,7 @@ async def enable_away_mode_by_calendar(
value=_party_mode_code(start=start, end=end, away_temperature=away_temperature),
)

@service
@service()
async def enable_away_mode_by_duration(self, hours: int, away_temperature: float) -> None:
"""Enable the away mode by duration on thermostat."""
start = datetime.now() - timedelta(minutes=10)
Expand All @@ -394,7 +394,7 @@ async def enable_away_mode_by_duration(self, hours: int, away_temperature: float
start=start, end=end, away_temperature=away_temperature
)

@service
@service()
async def disable_away_mode(self) -> None:
"""Disable the away mode on thermostat."""
start = datetime.now() - timedelta(hours=11)
Expand Down Expand Up @@ -551,7 +551,7 @@ async def set_preset_mode(
if profile_idx := self._profiles.get(preset_mode):
await self._e_active_profile.send_value(value=profile_idx, collector=collector)

@service
@service()
async def enable_away_mode_by_calendar(
self, start: datetime, end: datetime, away_temperature: float
) -> None:
Expand All @@ -567,7 +567,7 @@ async def enable_away_mode_by_calendar(
},
)

@service
@service()
async def enable_away_mode_by_duration(self, hours: int, away_temperature: float) -> None:
"""Enable the away mode by duration on thermostat."""
start = datetime.now() - timedelta(minutes=10)
Expand All @@ -576,7 +576,7 @@ async def enable_away_mode_by_duration(self, hours: int, away_temperature: float
start=start, end=end, away_temperature=away_temperature
)

@service
@service()
async def disable_away_mode(self) -> None:
"""Disable the away mode on thermostat."""
await self._client.put_paramset(
Expand Down
2 changes: 1 addition & 1 deletion hahomematic/platforms/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ async def refresh_data() -> None:
if refresh_after_update_intervals:
self._central.looper.create_task(target=refresh_data(), name="refresh_firmware_data")

return update_result
return update_result # type: ignore[no-any-return]

async def load_value_cache(self) -> None:
"""Init the parameter cache."""
Expand Down
Loading

0 comments on commit 7dcd3dc

Please sign in to comment.