Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/haclient/domains/air_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Any

from haclient.core.plugins import DomainSpec, register_domain
from haclient.entity.base import Entity
from haclient.entity.base import Entity, ValueChangeHandler


def _coerce_numeric(value: Any) -> float | int | None:
Expand Down Expand Up @@ -63,7 +63,7 @@ class AirQuality(Entity):

# -- Listener decorators ------------------------------------------

def on_aqi_change(self, func: Any) -> Any:
def on_aqi_change(self, func: ValueChangeHandler) -> ValueChangeHandler:
"""Register a listener for Air Quality Index changes.

Fires whenever the entity *state* string changes, which mirrors
Expand All @@ -81,7 +81,7 @@ def on_aqi_change(self, func: Any) -> Any:
"""
return self._register_state_value_listener(func)

def on_pm25_change(self, func: Any) -> Any:
def on_pm25_change(self, func: ValueChangeHandler) -> ValueChangeHandler:
"""Register a listener for PM2.5 attribute changes.

Parameters
Expand All @@ -97,7 +97,7 @@ def on_pm25_change(self, func: Any) -> Any:
"""
return self._register_attr_listener("particulate_matter_2_5", func)

def on_co2_change(self, func: Any) -> Any:
def on_co2_change(self, func: ValueChangeHandler) -> ValueChangeHandler:
"""Register a listener for CO2 attribute changes.

Parameters
Expand Down
16 changes: 7 additions & 9 deletions src/haclient/domains/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

from __future__ import annotations

from typing import Any

from haclient.core.plugins import DomainSpec, register_domain
from haclient.entity.base import Entity
from haclient.entity.base import Entity, ValueChangeHandler


class BinarySensor(Entity):
Expand All @@ -20,14 +18,14 @@ class BinarySensor(Entity):

# -- Listener decorators ------------------------------------------

def on_activate(self, func: Any) -> Any:
def on_activate(self, func: ValueChangeHandler) -> ValueChangeHandler:
"""Register a listener for when the sensor activates (state ``on``).

Parameters
----------
func : callable
Sync or async zero-argument callable invoked on every
transition into the ``on`` state.
Sync or async callable invoked with ``(old_state, new_state)``
on every transition into the ``on`` state.

Returns
-------
Expand All @@ -37,14 +35,14 @@ def on_activate(self, func: Any) -> Any:
"""
return self._register_state_transition_listener("on", func)

def on_deactivate(self, func: Any) -> Any:
def on_deactivate(self, func: ValueChangeHandler) -> ValueChangeHandler:
"""Register a listener for when the sensor deactivates (state ``off``).

Parameters
----------
func : callable
Sync or async zero-argument callable invoked on every
transition into the ``off`` state.
Sync or async callable invoked with ``(old_state, new_state)``
on every transition into the ``off`` state.

Returns
-------
Expand Down
17 changes: 10 additions & 7 deletions src/haclient/domains/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Any

from haclient.core.plugins import DomainSpec, register_domain
from haclient.entity.base import Entity
from haclient.entity.base import Entity, ValueChangeHandler


class Climate(Entity):
Expand All @@ -19,13 +19,14 @@ class Climate(Entity):

# -- Listener decorators ------------------------------------------

def on_hvac_mode_change(self, func: Any) -> Any:
def on_hvac_mode_change(self, func: ValueChangeHandler) -> ValueChangeHandler:
"""Register a listener for HVAC mode changes.

Parameters
----------
func : callable
Callable receiving the new HVAC mode string (e.g. ``"heat"``).
Sync or async callable invoked with ``(old_state, new_state)``
HVAC mode strings (e.g. ``("cool", "heat")``).

Returns
-------
Expand All @@ -34,13 +35,14 @@ def on_hvac_mode_change(self, func: Any) -> Any:
"""
return self._register_state_value_listener(func)

def on_temperature_change(self, func: Any) -> Any:
def on_temperature_change(self, func: ValueChangeHandler) -> ValueChangeHandler:
"""Register a listener for current temperature changes.

Parameters
----------
func : callable
Callable receiving the new ``current_temperature`` value.
Callable invoked with ``(old_value, new_value)`` whenever
the ``current_temperature`` attribute changes.

Returns
-------
Expand All @@ -49,13 +51,14 @@ def on_temperature_change(self, func: Any) -> Any:
"""
return self._register_attr_listener("current_temperature", func)

def on_target_temperature_change(self, func: Any) -> Any:
def on_target_temperature_change(self, func: ValueChangeHandler) -> ValueChangeHandler:
"""Register a listener for target temperature changes.

Parameters
----------
func : callable
Callable receiving the new target temperature value.
Callable invoked with ``(old_value, new_value)`` whenever
the ``temperature`` (target temperature) attribute changes.

Returns
-------
Expand Down
22 changes: 10 additions & 12 deletions src/haclient/domains/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

from __future__ import annotations

from typing import Any

from haclient.core.plugins import DomainSpec, register_domain
from haclient.entity.base import Entity
from haclient.entity.base import Entity, ValueChangeHandler


class Cover(Entity):
Expand All @@ -19,14 +17,14 @@ class Cover(Entity):

# -- Listener decorators ------------------------------------------

def on_open(self, func: Any) -> Any:
def on_open(self, func: ValueChangeHandler) -> ValueChangeHandler:
"""Register a listener for when the cover opens.

Parameters
----------
func : callable
Sync or async zero-argument callable invoked on every
transition into the ``open`` state.
Sync or async callable invoked with ``(old_state, new_state)``
on every transition into the ``open`` state.

Returns
-------
Expand All @@ -35,14 +33,14 @@ def on_open(self, func: Any) -> Any:
"""
return self._register_state_transition_listener("open", func)

def on_close(self, func: Any) -> Any:
def on_close(self, func: ValueChangeHandler) -> ValueChangeHandler:
"""Register a listener for when the cover closes.

Parameters
----------
func : callable
Sync or async zero-argument callable invoked on every
transition into the ``closed`` state.
Sync or async callable invoked with ``(old_state, new_state)``
on every transition into the ``closed`` state.

Returns
-------
Expand All @@ -51,14 +49,14 @@ def on_close(self, func: Any) -> Any:
"""
return self._register_state_transition_listener("closed", func)

def on_position_change(self, func: Any) -> Any:
def on_position_change(self, func: ValueChangeHandler) -> ValueChangeHandler:
"""Register a listener for position changes.

Parameters
----------
func : callable
Callable receiving the new ``current_position`` value
(0-100).
Callable invoked with ``(old_value, new_value)`` whenever
the ``current_position`` attribute (0-100) changes.

Returns
-------
Expand Down
11 changes: 5 additions & 6 deletions src/haclient/domains/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
from __future__ import annotations

import logging
from typing import Any

from haclient.core.plugins import DomainSpec, register_domain
from haclient.entity.base import Entity
from haclient.entity.base import Entity, ValueChangeHandler

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -44,7 +43,7 @@ class Fan(Entity):

# -- Listener decorators ------------------------------------------

def on_turn_on(self, func: Any) -> Any:
def on_turn_on(self, func: ValueChangeHandler) -> ValueChangeHandler:
"""Register a listener for when the fan turns on.

Parameters
Expand All @@ -60,7 +59,7 @@ def on_turn_on(self, func: Any) -> Any:
"""
return self._register_state_transition_listener("on", func)

def on_turn_off(self, func: Any) -> Any:
def on_turn_off(self, func: ValueChangeHandler) -> ValueChangeHandler:
"""Register a listener for when the fan turns off.

Parameters
Expand All @@ -76,7 +75,7 @@ def on_turn_off(self, func: Any) -> Any:
"""
return self._register_state_transition_listener("off", func)

def on_speed_change(self, func: Any) -> Any:
def on_speed_change(self, func: ValueChangeHandler) -> ValueChangeHandler:
"""Register a listener for fan speed (``percentage``) changes.

Parameters
Expand All @@ -92,7 +91,7 @@ def on_speed_change(self, func: Any) -> Any:
"""
return self._register_attr_listener("percentage", func)

def on_direction_change(self, func: Any) -> Any:
def on_direction_change(self, func: ValueChangeHandler) -> ValueChangeHandler:
"""Register a listener for fan direction changes.

Parameters
Expand Down
26 changes: 13 additions & 13 deletions src/haclient/domains/humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

from __future__ import annotations

from typing import Any

from haclient.core.plugins import DomainSpec, register_domain
from haclient.entity.base import Entity
from haclient.entity.base import Entity, ValueChangeHandler


class Humidifier(Entity):
Expand All @@ -26,14 +24,14 @@ class Humidifier(Entity):

# -- Listener decorators ------------------------------------------

def on_turn_on(self, func: Any) -> Any:
def on_turn_on(self, func: ValueChangeHandler) -> ValueChangeHandler:
"""Register a listener for when the humidifier turns on.

Parameters
----------
func : callable
Sync or async zero-argument callable invoked on every
transition into the ``on`` state.
Sync or async callable invoked with ``(old_state, new_state)``
on every transition into the ``on`` state.

Returns
-------
Expand All @@ -42,14 +40,14 @@ def on_turn_on(self, func: Any) -> Any:
"""
return self._register_state_transition_listener("on", func)

def on_turn_off(self, func: Any) -> Any:
def on_turn_off(self, func: ValueChangeHandler) -> ValueChangeHandler:
"""Register a listener for when the humidifier turns off.

Parameters
----------
func : callable
Sync or async zero-argument callable invoked on every
transition into the ``off`` state.
Sync or async callable invoked with ``(old_state, new_state)``
on every transition into the ``off`` state.

Returns
-------
Expand All @@ -58,13 +56,14 @@ def on_turn_off(self, func: Any) -> Any:
"""
return self._register_state_transition_listener("off", func)

def on_humidity_change(self, func: Any) -> Any:
def on_humidity_change(self, func: ValueChangeHandler) -> ValueChangeHandler:
"""Register a listener for target humidity changes.

Parameters
----------
func : callable
Callable receiving the new target ``humidity`` value.
Callable invoked with ``(old_value, new_value)`` whenever
the target ``humidity`` attribute changes.

Returns
-------
Expand All @@ -73,13 +72,14 @@ def on_humidity_change(self, func: Any) -> Any:
"""
return self._register_attr_listener("humidity", func)

def on_mode_change(self, func: Any) -> Any:
def on_mode_change(self, func: ValueChangeHandler) -> ValueChangeHandler:
"""Register a listener for operating mode changes.

Parameters
----------
func : callable
Callable receiving the new mode string.
Callable invoked with ``(old_value, new_value)`` whenever
the ``mode`` attribute changes.

Returns
-------
Expand Down
Loading
Loading