Skip to content

Commit

Permalink
Add wait_for_callback to collector (#1521)
Browse files Browse the repository at this point in the history
* Add wait_for_callback to collector

* Fix tests
  • Loading branch information
SukramJ authored Apr 21, 2024
1 parent d6d89e6 commit dc11487
Show file tree
Hide file tree
Showing 15 changed files with 394 additions and 107 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Version 2024.4.10 (2024-04-21)

- Add wait_for_callback to collector

# Version 2024.4.9 (2024-04-20)

- Decompose combined parameter
Expand Down
10 changes: 5 additions & 5 deletions hahomematic/platforms/custom/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def _min_or_target_temperature(self) -> float:
return self.min_temp
return temperature

@bind_collector
@bind_collector()
async def set_temperature(
self,
temperature: float,
Expand Down Expand Up @@ -331,7 +331,7 @@ def supports_preset(self) -> bool:
"""Flag if climate supports preset."""
return True

@bind_collector
@bind_collector()
async def set_hvac_mode(
self, hvac_mode: HvacMode, collector: CallParameterCollector | None = None
) -> None:
Expand All @@ -352,7 +352,7 @@ async def set_hvac_mode(
temperature=_OFF_TEMPERATURE, collector=collector, do_validate=False
)

@bind_collector
@bind_collector()
async def set_preset_mode(
self, preset_mode: PresetMode, collector: CallParameterCollector | None = None
) -> None:
Expand Down Expand Up @@ -501,7 +501,7 @@ def supports_preset(self) -> bool:
"""Flag if climate supports preset."""
return True

@bind_collector
@bind_collector()
async def set_hvac_mode(
self, hvac_mode: HvacMode, collector: CallParameterCollector | None = None
) -> None:
Expand All @@ -523,7 +523,7 @@ async def set_hvac_mode(
await self._e_control_mode.send_value(value=ModeHmIP.MANU, collector=collector)
await self.set_temperature(temperature=_OFF_TEMPERATURE, collector=collector)

@bind_collector
@bind_collector()
async def set_preset_mode(
self, preset_mode: PresetMode, collector: CallParameterCollector | None = None
) -> None:
Expand Down
30 changes: 15 additions & 15 deletions hahomematic/platforms/custom/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def current_position(self) -> int:
"""Return current position of cover."""
return int(self._channel_level * 100)

@bind_collector
@bind_collector()
async def set_position(
self,
position: int | None = None,
Expand Down Expand Up @@ -157,21 +157,21 @@ def is_closing(self) -> bool | None:
return str(self._e_direction.value) == CoverActivity.CLOSING
return None

@bind_collector
@bind_collector()
async def open(self, collector: CallParameterCollector | None = None) -> None:
"""Open the cover."""
if not self.is_state_change(open=True):
return
await self._set_level(level=self._open_level, collector=collector)

@bind_collector
@bind_collector()
async def close(self, collector: CallParameterCollector | None = None) -> None:
"""Close the cover."""
if not self.is_state_change(close=True):
return
await self._set_level(level=self._closed_level, collector=collector)

@bind_collector
@bind_collector()
async def stop(self, collector: CallParameterCollector | None = None) -> None:
"""Stop the device if in motion."""
await self._e_stop.send_value(value=True, collector=collector)
Expand Down Expand Up @@ -253,7 +253,7 @@ def current_tilt_position(self) -> int:
"""Return current tilt position of cover."""
return int(self._channel_tilt_level * 100)

@bind_collector
@bind_collector()
async def set_position(
self,
position: int | None = None,
Expand Down Expand Up @@ -291,21 +291,21 @@ async def _set_level(
await self._e_level_2.send_value(value=_tilt_level, collector=collector)
await super()._set_level(level=_level, collector=collector)

@bind_collector
@bind_collector()
async def open_tilt(self, collector: CallParameterCollector | None = None) -> None:
"""Open the tilt."""
if not self.is_state_change(tilt_open=True):
return
await self._set_level(tilt_level=self._open_level, collector=collector)

@bind_collector
@bind_collector()
async def close_tilt(self, collector: CallParameterCollector | None = None) -> None:
"""Close the tilt."""
if not self.is_state_change(tilt_close=True):
return
await self._set_level(tilt_level=self._closed_level, collector=collector)

@bind_collector
@bind_collector()
async def stop_tilt(self, collector: CallParameterCollector | None = None) -> None:
"""Stop the device if in motion."""
await self._e_stop.send_value(value=True, collector=collector)
Expand Down Expand Up @@ -364,7 +364,7 @@ def channel_operation_mode(self) -> str | None:
"""Return channel_operation_mode of cover."""
return self._e_channel_operation_mode.value

@bind_collector
@bind_collector()
async def open(self, collector: CallParameterCollector | None = None) -> None:
"""Open the cover and open the tilt."""
if not self.is_state_change(open=True, tilt_open=True):
Expand All @@ -375,7 +375,7 @@ async def open(self, collector: CallParameterCollector | None = None) -> None:
collector=collector,
)

@bind_collector
@bind_collector()
async def close(self, collector: CallParameterCollector | None = None) -> None:
"""Close the cover and close the tilt."""
if not self.is_state_change(close=True, tilt_close=True):
Expand Down Expand Up @@ -430,7 +430,7 @@ def current_position(self) -> int | None:
return CoverPosition.CLOSED
return None

@bind_collector
@bind_collector()
async def set_position(
self,
position: int | None = None,
Expand Down Expand Up @@ -468,26 +468,26 @@ def is_closing(self) -> bool | None:
return int(self._e_section.value) == GarageDoorActivity.CLOSING
return None

@bind_collector
@bind_collector()
async def open(self, collector: CallParameterCollector | None = None) -> None:
"""Open the garage door."""
if not self.is_state_change(open=True):
return
await self._e_door_command.send_value(value=GarageDoorCommand.OPEN, collector=collector)

@bind_collector
@bind_collector()
async def close(self, collector: CallParameterCollector | None = None) -> None:
"""Close the garage door."""
if not self.is_state_change(close=True):
return
await self._e_door_command.send_value(value=GarageDoorCommand.CLOSE, collector=collector)

@bind_collector
@bind_collector()
async def stop(self, collector: CallParameterCollector | None = None) -> None:
"""Stop the device if in motion."""
await self._e_door_command.send_value(value=GarageDoorCommand.STOP, collector=collector)

@bind_collector
@bind_collector()
async def vent(self, collector: CallParameterCollector | None = None) -> None:
"""Move the garage door to vent position."""
if not self.is_state_change(vent=True):
Expand Down
26 changes: 13 additions & 13 deletions hahomematic/platforms/custom/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def effects(self) -> tuple[str, ...] | None:
"""Return the supported effects."""
return None

@bind_collector
@bind_collector()
async def turn_on(
self, collector: CallParameterCollector | None = None, **kwargs: Unpack[LightOnArgs]
) -> None:
Expand All @@ -245,7 +245,7 @@ async def turn_on(
level = brightness / _MAX_BRIGHTNESS
await self._e_level.send_value(value=level, collector=collector)

@bind_collector
@bind_collector()
async def turn_off(
self, collector: CallParameterCollector | None = None, **kwargs: Unpack[LightOffArgs]
) -> None:
Expand All @@ -257,7 +257,7 @@ async def turn_off(

await self._e_level.send_value(value=_DIMMER_OFF, collector=collector)

@bind_collector
@bind_collector()
async def _set_on_time_value(
self, on_time: float, collector: CallParameterCollector | None = None
) -> None:
Expand Down Expand Up @@ -333,7 +333,7 @@ def hs_color(self) -> tuple[float, float] | None:
return color / 200 * 360, 100
return 0.0, 0.0

@bind_collector
@bind_collector()
async def turn_on(
self, collector: CallParameterCollector | None = None, **kwargs: Unpack[LightOnArgs]
) -> None:
Expand Down Expand Up @@ -379,7 +379,7 @@ def effects(self) -> tuple[str, ...] | None:
"""Return the supported effects."""
return self._effects

@bind_collector
@bind_collector()
async def turn_on(
self, collector: CallParameterCollector | None = None, **kwargs: Unpack[LightOnArgs]
) -> None:
Expand Down Expand Up @@ -417,7 +417,7 @@ def color_temp(self) -> int | None:
"""Return the color temperature in mireds of this light between min/max mireds."""
return int(_MAX_MIREDS - (_MAX_MIREDS - _MIN_MIREDS) * (self._e_color_level.value or 0.0))

@bind_collector
@bind_collector()
async def turn_on(
self, collector: CallParameterCollector | None = None, **kwargs: Unpack[LightOnArgs]
) -> None:
Expand Down Expand Up @@ -532,7 +532,7 @@ def effects(self) -> tuple[str, ...] | None:
"""Return the supported effects."""
return self._e_effect.values or ()

@bind_collector
@bind_collector()
async def turn_on(
self, collector: CallParameterCollector | None = None, **kwargs: Unpack[LightOnArgs]
) -> None:
Expand All @@ -557,7 +557,7 @@ async def turn_on(

await super().turn_on(collector=collector, **kwargs)

@bind_collector
@bind_collector()
async def _set_on_time_value(
self, on_time: float, collector: CallParameterCollector | None = None
) -> None:
Expand Down Expand Up @@ -639,7 +639,7 @@ def effects(self) -> tuple[str, ...] | None:
"""Return the supported effects."""
return self._e_effect.values or ()

@bind_collector
@bind_collector()
async def turn_on(
self, collector: CallParameterCollector | None = None, **kwargs: Unpack[LightOnArgs]
) -> None:
Expand All @@ -664,7 +664,7 @@ async def turn_on(

await super().turn_on(collector=collector, **kwargs)

@bind_collector
@bind_collector()
async def _set_on_time_value(
self, on_time: float, collector: CallParameterCollector | None = None
) -> None:
Expand Down Expand Up @@ -741,7 +741,7 @@ def channel_hs_color(self) -> tuple[float, float] | None:
return _FIXED_COLOR_SWITCHER.get(self._e_channel_color.value, (0.0, 0.0))
return None

@bind_collector
@bind_collector()
async def turn_on(
self, collector: CallParameterCollector | None = None, **kwargs: Unpack[LightOnArgs]
) -> None:
Expand All @@ -756,7 +756,7 @@ async def turn_on(

await super().turn_on(collector=collector, **kwargs)

@bind_collector
@bind_collector()
async def _set_on_time_value(
self, on_time: float, collector: CallParameterCollector | None = None
) -> None:
Expand Down Expand Up @@ -807,7 +807,7 @@ def effects(self) -> tuple[str, ...] | None:
"""Return the supported effects."""
return self._effect_list

@bind_collector
@bind_collector()
async def turn_on(
self, collector: CallParameterCollector | None = None, **kwargs: Unpack[LightOnArgs]
) -> None:
Expand Down
12 changes: 6 additions & 6 deletions hahomematic/platforms/custom/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ def is_jammed(self) -> bool:
"""Return true if lock is jammed."""
return False

@bind_collector
@bind_collector()
async def lock(self, collector: CallParameterCollector | None = None) -> None:
"""Lock the lock."""
await self._e_lock_target_level.send_value(value=LockState.LOCKED, collector=collector)

@bind_collector
@bind_collector()
async def unlock(self, collector: CallParameterCollector | None = None) -> None:
"""Unlock the lock."""
await self._e_lock_target_level.send_value(value=LockState.UNLOCKED, collector=collector)

@bind_collector
@bind_collector()
async def open(self, collector: CallParameterCollector | None = None) -> None:
"""Open the lock."""
await self._e_lock_target_level.send_value(value=LockState.OPEN, collector=collector)
Expand Down Expand Up @@ -167,17 +167,17 @@ def is_jammed(self) -> bool:
"""Return true if lock is jammed."""
return self._e_error.value is not None and self._e_error.value != LockState.NO_ERROR

@bind_collector
@bind_collector()
async def lock(self, collector: CallParameterCollector | None = None) -> None:
"""Lock the lock."""
await self._e_state.send_value(value=False, collector=collector)

@bind_collector
@bind_collector()
async def unlock(self, collector: CallParameterCollector | None = None) -> None:
"""Unlock the lock."""
await self._e_state.send_value(value=True, collector=collector)

@bind_collector
@bind_collector()
async def open(self, collector: CallParameterCollector | None = None) -> None:
"""Open the lock."""
await self._e_open.send_value(value=True, collector=collector)
Expand Down
4 changes: 2 additions & 2 deletions hahomematic/platforms/custom/siren.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def supports_duration(self) -> bool:
"""Flag if siren supports duration."""
return True

@bind_collector
@bind_collector()
async def turn_on(
self,
collector: CallParameterCollector | None = None,
Expand Down Expand Up @@ -167,7 +167,7 @@ async def turn_on(
duration = kwargs.get("duration", self._e_duration.default)
await self._e_duration.send_value(value=duration, collector=collector)

@bind_collector
@bind_collector()
async def turn_off(self, collector: CallParameterCollector | None = None) -> None:
"""Turn the device off."""
await self._e_acoustic_alarm_selection.send_value(
Expand Down
4 changes: 2 additions & 2 deletions hahomematic/platforms/custom/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def value(self) -> bool | None:
"""Return the current value of the switch."""
return self._e_state.value

@bind_collector
@bind_collector()
async def turn_on(
self, collector: CallParameterCollector | None = None, on_time: float | None = None
) -> None:
Expand All @@ -73,7 +73,7 @@ async def turn_on(
await self._e_on_time_value.send_value(value=float(on_time), collector=collector)
await self._e_state.turn_on(collector=collector)

@bind_collector
@bind_collector()
async def turn_off(self, collector: CallParameterCollector | None = None) -> None:
"""Turn the switch off."""
if not self.is_state_change(off=True):
Expand Down
Loading

0 comments on commit dc11487

Please sign in to comment.