mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
Improve categorization of features (#904)
This updates the categorization of features and makes the id mandatory for features
This commit is contained in:
parent
50b5107f75
commit
55653d0346
@ -62,6 +62,8 @@ class Feature:
|
|||||||
|
|
||||||
#: Device instance required for getting and setting values
|
#: Device instance required for getting and setting values
|
||||||
device: Device
|
device: Device
|
||||||
|
#: Identifier
|
||||||
|
id: str
|
||||||
#: User-friendly short description
|
#: User-friendly short description
|
||||||
name: str
|
name: str
|
||||||
#: Name of the property that allows accessing the value
|
#: Name of the property that allows accessing the value
|
||||||
@ -99,15 +101,8 @@ class Feature:
|
|||||||
#: If set, this property will be used to set *choices*.
|
#: If set, this property will be used to set *choices*.
|
||||||
choices_getter: str | None = None
|
choices_getter: str | None = None
|
||||||
|
|
||||||
#: Identifier
|
|
||||||
id: str | None = None
|
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
"""Handle late-binding of members."""
|
"""Handle late-binding of members."""
|
||||||
# Set id, if unset
|
|
||||||
if self.id is None:
|
|
||||||
self.id = self.name.lower().replace(" ", "_")
|
|
||||||
|
|
||||||
# Populate minimum & maximum values, if range_getter is given
|
# Populate minimum & maximum values, if range_getter is given
|
||||||
container = self.container if self.container is not None else self.device
|
container = self.container if self.container is not None else self.device
|
||||||
if self.range_getter is not None:
|
if self.range_getter is not None:
|
||||||
|
@ -213,6 +213,7 @@ class IotBulb(IotDevice, Bulb):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device=self,
|
device=self,
|
||||||
|
id="brightness",
|
||||||
name="Brightness",
|
name="Brightness",
|
||||||
attribute_getter="brightness",
|
attribute_getter="brightness",
|
||||||
attribute_setter="set_brightness",
|
attribute_setter="set_brightness",
|
||||||
@ -227,6 +228,7 @@ class IotBulb(IotDevice, Bulb):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device=self,
|
device=self,
|
||||||
|
id="color_temperature",
|
||||||
name="Color temperature",
|
name="Color temperature",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="color_temp",
|
attribute_getter="color_temp",
|
||||||
|
@ -334,6 +334,7 @@ class IotDevice(Device):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device=self,
|
device=self,
|
||||||
|
id="rssi",
|
||||||
name="RSSI",
|
name="RSSI",
|
||||||
attribute_getter="rssi",
|
attribute_getter="rssi",
|
||||||
icon="mdi:signal",
|
icon="mdi:signal",
|
||||||
@ -344,6 +345,7 @@ class IotDevice(Device):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device=self,
|
device=self,
|
||||||
|
id="on_since",
|
||||||
name="On since",
|
name="On since",
|
||||||
attribute_getter="on_since",
|
attribute_getter="on_since",
|
||||||
icon="mdi:clock",
|
icon="mdi:clock",
|
||||||
|
@ -91,12 +91,15 @@ class IotDimmer(IotPlug):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device=self,
|
device=self,
|
||||||
|
id="brightness",
|
||||||
name="Brightness",
|
name="Brightness",
|
||||||
attribute_getter="brightness",
|
attribute_getter="brightness",
|
||||||
attribute_setter="set_brightness",
|
attribute_setter="set_brightness",
|
||||||
minimum_value=1,
|
minimum_value=1,
|
||||||
maximum_value=100,
|
maximum_value=100,
|
||||||
|
unit="%",
|
||||||
type=Feature.Type.Number,
|
type=Feature.Type.Number,
|
||||||
|
category=Feature.Category.Primary,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -65,6 +65,7 @@ class IotPlug(IotDevice):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device=self,
|
device=self,
|
||||||
|
id="led",
|
||||||
name="LED",
|
name="LED",
|
||||||
icon="mdi:led-{state}",
|
icon="mdi:led-{state}",
|
||||||
attribute_getter="led",
|
attribute_getter="led",
|
||||||
|
@ -22,10 +22,13 @@ class AmbientLight(IotModule):
|
|||||||
Feature(
|
Feature(
|
||||||
device=device,
|
device=device,
|
||||||
container=self,
|
container=self,
|
||||||
|
id="ambient_light",
|
||||||
name="Ambient Light",
|
name="Ambient Light",
|
||||||
icon="mdi:brightness-percent",
|
icon="mdi:brightness-percent",
|
||||||
attribute_getter="ambientlight_brightness",
|
attribute_getter="ambientlight_brightness",
|
||||||
type=Feature.Type.Sensor,
|
type=Feature.Type.Sensor,
|
||||||
|
category=Feature.Category.Primary,
|
||||||
|
unit="%",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,10 +30,12 @@ class Cloud(IotModule):
|
|||||||
Feature(
|
Feature(
|
||||||
device=device,
|
device=device,
|
||||||
container=self,
|
container=self,
|
||||||
|
id="cloud_connection",
|
||||||
name="Cloud connection",
|
name="Cloud connection",
|
||||||
icon="mdi:cloud",
|
icon="mdi:cloud",
|
||||||
attribute_getter="is_connected",
|
attribute_getter="is_connected",
|
||||||
type=Feature.Type.BinarySensor,
|
type=Feature.Type.BinarySensor,
|
||||||
|
category=Feature.Category.Info,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ class Emeter(Usage):
|
|||||||
unit="W",
|
unit="W",
|
||||||
id="current_power_w", # for homeassistant backwards compat
|
id="current_power_w", # for homeassistant backwards compat
|
||||||
precision_hint=1,
|
precision_hint=1,
|
||||||
|
category=Feature.Category.Primary,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
@ -35,16 +36,19 @@ class Emeter(Usage):
|
|||||||
unit="kWh",
|
unit="kWh",
|
||||||
id="today_energy_kwh", # for homeassistant backwards compat
|
id="today_energy_kwh", # for homeassistant backwards compat
|
||||||
precision_hint=3,
|
precision_hint=3,
|
||||||
|
category=Feature.Category.Info,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
|
id="consumption_this_month",
|
||||||
name="This month's consumption",
|
name="This month's consumption",
|
||||||
attribute_getter="emeter_this_month",
|
attribute_getter="emeter_this_month",
|
||||||
container=self,
|
container=self,
|
||||||
unit="kWh",
|
unit="kWh",
|
||||||
precision_hint=3,
|
precision_hint=3,
|
||||||
|
category=Feature.Category.Info,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
@ -56,6 +60,7 @@ class Emeter(Usage):
|
|||||||
unit="kWh",
|
unit="kWh",
|
||||||
id="total_energy_kwh", # for homeassistant backwards compat
|
id="total_energy_kwh", # for homeassistant backwards compat
|
||||||
precision_hint=3,
|
precision_hint=3,
|
||||||
|
category=Feature.Category.Info,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
@ -67,6 +72,7 @@ class Emeter(Usage):
|
|||||||
unit="V",
|
unit="V",
|
||||||
id="voltage", # for homeassistant backwards compat
|
id="voltage", # for homeassistant backwards compat
|
||||||
precision_hint=1,
|
precision_hint=1,
|
||||||
|
category=Feature.Category.Primary,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
@ -78,6 +84,7 @@ class Emeter(Usage):
|
|||||||
unit="A",
|
unit="A",
|
||||||
id="current_a", # for homeassistant backwards compat
|
id="current_a", # for homeassistant backwards compat
|
||||||
precision_hint=2,
|
precision_hint=2,
|
||||||
|
category=Feature.Category.Primary,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -53,14 +53,10 @@ class Module(ABC):
|
|||||||
|
|
||||||
def _add_feature(self, feature: Feature):
|
def _add_feature(self, feature: Feature):
|
||||||
"""Add module feature."""
|
"""Add module feature."""
|
||||||
|
id_ = feature.id
|
||||||
def _slugified_name(name):
|
if id_ in self._module_features:
|
||||||
return name.lower().replace(" ", "_").replace("'", "_")
|
raise KasaException("Duplicate id detected %s" % id_)
|
||||||
|
self._module_features[id_] = feature
|
||||||
feat_name = _slugified_name(feature.name)
|
|
||||||
if feat_name in self._module_features:
|
|
||||||
raise KasaException("Duplicate name detected %s" % feat_name)
|
|
||||||
self._module_features[feat_name] = feature
|
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return (
|
return (
|
||||||
|
@ -27,7 +27,8 @@ class AlarmModule(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Alarm",
|
id="alarm",
|
||||||
|
name="Alarm",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="active",
|
attribute_getter="active",
|
||||||
icon="mdi:bell",
|
icon="mdi:bell",
|
||||||
@ -37,7 +38,8 @@ class AlarmModule(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Alarm source",
|
id="alarm_source",
|
||||||
|
name="Alarm source",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="source",
|
attribute_getter="source",
|
||||||
icon="mdi:bell",
|
icon="mdi:bell",
|
||||||
@ -46,7 +48,8 @@ class AlarmModule(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Alarm sound",
|
id="alarm_sound",
|
||||||
|
name="Alarm sound",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="alarm_sound",
|
attribute_getter="alarm_sound",
|
||||||
attribute_setter="set_alarm_sound",
|
attribute_setter="set_alarm_sound",
|
||||||
@ -58,7 +61,8 @@ class AlarmModule(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Alarm volume",
|
id="alarm_volume",
|
||||||
|
name="Alarm volume",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="alarm_volume",
|
attribute_getter="alarm_volume",
|
||||||
attribute_setter="set_alarm_volume",
|
attribute_setter="set_alarm_volume",
|
||||||
@ -70,7 +74,8 @@ class AlarmModule(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Test alarm",
|
id="test_alarm",
|
||||||
|
name="Test alarm",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_setter="play",
|
attribute_setter="play",
|
||||||
type=Feature.Type.Action,
|
type=Feature.Type.Action,
|
||||||
@ -79,7 +84,8 @@ class AlarmModule(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Stop alarm",
|
id="stop_alarm",
|
||||||
|
name="Stop alarm",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_setter="stop",
|
attribute_setter="stop",
|
||||||
type=Feature.Type.Action,
|
type=Feature.Type.Action,
|
||||||
|
@ -23,7 +23,8 @@ class AutoOffModule(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Auto off enabled",
|
id="auto_off_enabled",
|
||||||
|
name="Auto off enabled",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="enabled",
|
attribute_getter="enabled",
|
||||||
attribute_setter="set_enabled",
|
attribute_setter="set_enabled",
|
||||||
@ -33,7 +34,8 @@ class AutoOffModule(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Auto off minutes",
|
id="auto_off_minutes",
|
||||||
|
name="Auto off minutes",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="delay",
|
attribute_getter="delay",
|
||||||
attribute_setter="set_delay",
|
attribute_setter="set_delay",
|
||||||
@ -42,7 +44,12 @@ class AutoOffModule(SmartModule):
|
|||||||
)
|
)
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device, "Auto off at", container=self, attribute_getter="auto_off_at"
|
device,
|
||||||
|
id="auto_off_at",
|
||||||
|
name="Auto off at",
|
||||||
|
container=self,
|
||||||
|
attribute_getter="auto_off_at",
|
||||||
|
category=Feature.Category.Info,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,20 +22,25 @@ class BatterySensor(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
|
"battery_level",
|
||||||
"Battery level",
|
"Battery level",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="battery",
|
attribute_getter="battery",
|
||||||
icon="mdi:battery",
|
icon="mdi:battery",
|
||||||
|
unit="%",
|
||||||
|
category=Feature.Category.Info,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
|
"battery_low",
|
||||||
"Battery low",
|
"Battery low",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="battery_low",
|
attribute_getter="battery_low",
|
||||||
icon="mdi:alert",
|
icon="mdi:alert",
|
||||||
type=Feature.Type.BinarySensor,
|
type=Feature.Type.BinarySensor,
|
||||||
|
category=Feature.Category.Debug,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,7 +25,8 @@ class Brightness(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Brightness",
|
id="brightness",
|
||||||
|
name="Brightness",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="brightness",
|
attribute_getter="brightness",
|
||||||
attribute_setter="set_brightness",
|
attribute_setter="set_brightness",
|
||||||
|
@ -24,11 +24,13 @@ class CloudModule(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Cloud connection",
|
id="cloud_connection",
|
||||||
|
name="Cloud connection",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="is_connected",
|
attribute_getter="is_connected",
|
||||||
icon="mdi:cloud",
|
icon="mdi:cloud",
|
||||||
type=Feature.Type.BinarySensor,
|
type=Feature.Type.BinarySensor,
|
||||||
|
category=Feature.Category.Info,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ class ColorModule(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
|
"hsv",
|
||||||
"HSV",
|
"HSV",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="hsv",
|
attribute_getter="hsv",
|
||||||
|
@ -28,6 +28,7 @@ class ColorTemperatureModule(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
|
"color_temperature",
|
||||||
"Color temperature",
|
"Color temperature",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="color_temp",
|
attribute_getter="color_temp",
|
||||||
|
@ -22,31 +22,37 @@ class EnergyModule(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
|
"consumption_current",
|
||||||
name="Current consumption",
|
name="Current consumption",
|
||||||
attribute_getter="current_power",
|
attribute_getter="current_power",
|
||||||
container=self,
|
container=self,
|
||||||
unit="W",
|
unit="W",
|
||||||
precision_hint=1,
|
precision_hint=1,
|
||||||
|
category=Feature.Category.Primary,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
|
"consumption_today",
|
||||||
name="Today's consumption",
|
name="Today's consumption",
|
||||||
attribute_getter="emeter_today",
|
attribute_getter="emeter_today",
|
||||||
container=self,
|
container=self,
|
||||||
unit="Wh",
|
unit="Wh",
|
||||||
precision_hint=2,
|
precision_hint=2,
|
||||||
|
category=Feature.Category.Info,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
|
"consumption_this_month",
|
||||||
name="This month's consumption",
|
name="This month's consumption",
|
||||||
attribute_getter="emeter_this_month",
|
attribute_getter="emeter_this_month",
|
||||||
container=self,
|
container=self,
|
||||||
unit="Wh",
|
unit="Wh",
|
||||||
precision_hint=2,
|
precision_hint=2,
|
||||||
|
category=Feature.Category.Info,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,7 +22,8 @@ class FanModule(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Fan speed level",
|
id="fan_speed_level",
|
||||||
|
name="Fan speed level",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="fan_speed_level",
|
attribute_getter="fan_speed_level",
|
||||||
attribute_setter="set_fan_speed_level",
|
attribute_setter="set_fan_speed_level",
|
||||||
@ -36,7 +37,8 @@ class FanModule(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Fan sleep mode",
|
id="fan_sleep_mode",
|
||||||
|
name="Fan sleep mode",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="sleep_mode",
|
attribute_getter="sleep_mode",
|
||||||
attribute_setter="set_sleep_mode",
|
attribute_setter="set_sleep_mode",
|
||||||
|
@ -52,7 +52,8 @@ class Firmware(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Auto update enabled",
|
id="auto_update_enabled",
|
||||||
|
name="Auto update enabled",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="auto_update_enabled",
|
attribute_getter="auto_update_enabled",
|
||||||
attribute_setter="set_auto_update_enabled",
|
attribute_setter="set_auto_update_enabled",
|
||||||
@ -62,10 +63,12 @@ class Firmware(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Update available",
|
id="update_available",
|
||||||
|
name="Update available",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="update_available",
|
attribute_getter="update_available",
|
||||||
type=Feature.Type.BinarySensor,
|
type=Feature.Type.BinarySensor,
|
||||||
|
category=Feature.Category.Info,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ class FrostProtectionModule(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
|
"frost_protection_enabled",
|
||||||
name="Frost protection enabled",
|
name="Frost protection enabled",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="enabled",
|
attribute_getter="enabled",
|
||||||
|
@ -22,21 +22,25 @@ class HumiditySensor(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Humidity",
|
id="humidity",
|
||||||
|
name="Humidity",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="humidity",
|
attribute_getter="humidity",
|
||||||
icon="mdi:water-percent",
|
icon="mdi:water-percent",
|
||||||
unit="%",
|
unit="%",
|
||||||
|
category=Feature.Category.Primary,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Humidity warning",
|
id="humidity_warning",
|
||||||
|
name="Humidity warning",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="humidity_warning",
|
attribute_getter="humidity_warning",
|
||||||
type=Feature.Type.BinarySensor,
|
type=Feature.Type.BinarySensor,
|
||||||
icon="mdi:alert",
|
icon="mdi:alert",
|
||||||
|
category=Feature.Category.Debug,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ class LedModule(SmartModule):
|
|||||||
Feature(
|
Feature(
|
||||||
device=device,
|
device=device,
|
||||||
container=self,
|
container=self,
|
||||||
|
id="led",
|
||||||
name="LED",
|
name="LED",
|
||||||
icon="mdi:led-{state}",
|
icon="mdi:led-{state}",
|
||||||
attribute_getter="led",
|
attribute_getter="led",
|
||||||
|
@ -34,7 +34,8 @@ class LightEffectModule(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Light effect",
|
id="light_effect",
|
||||||
|
name="Light effect",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="effect",
|
attribute_getter="effect",
|
||||||
attribute_setter="set_effect",
|
attribute_setter="set_effect",
|
||||||
|
@ -31,6 +31,7 @@ class LightTransitionModule(SmartModule):
|
|||||||
Feature(
|
Feature(
|
||||||
device=self._device,
|
device=self._device,
|
||||||
container=self,
|
container=self,
|
||||||
|
id="smooth_transitions",
|
||||||
name="Smooth transitions",
|
name="Smooth transitions",
|
||||||
icon=icon,
|
icon=icon,
|
||||||
attribute_getter="enabled_v1",
|
attribute_getter="enabled_v1",
|
||||||
@ -46,7 +47,8 @@ class LightTransitionModule(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
self._device,
|
self._device,
|
||||||
"Smooth transition on",
|
id="smooth_transition_on",
|
||||||
|
name="Smooth transition on",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="turn_on_transition",
|
attribute_getter="turn_on_transition",
|
||||||
attribute_setter="set_turn_on_transition",
|
attribute_setter="set_turn_on_transition",
|
||||||
@ -58,7 +60,8 @@ class LightTransitionModule(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
self._device,
|
self._device,
|
||||||
"Smooth transition off",
|
id="smooth_transition_off",
|
||||||
|
name="Smooth transition off",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="turn_off_transition",
|
attribute_getter="turn_off_transition",
|
||||||
attribute_setter="set_turn_off_transition",
|
attribute_setter="set_turn_off_transition",
|
||||||
|
@ -22,7 +22,8 @@ class ReportModule(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Report interval",
|
id="report_interval",
|
||||||
|
name="Report interval",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="report_interval",
|
attribute_getter="report_interval",
|
||||||
category=Feature.Category.Debug,
|
category=Feature.Category.Debug,
|
||||||
|
@ -22,7 +22,8 @@ class TemperatureSensor(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Temperature",
|
id="temperature",
|
||||||
|
name="Temperature",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="temperature",
|
attribute_getter="temperature",
|
||||||
icon="mdi:thermometer",
|
icon="mdi:thermometer",
|
||||||
@ -33,17 +34,20 @@ class TemperatureSensor(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Temperature warning",
|
id="temperature_warning",
|
||||||
|
name="Temperature warning",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="temperature_warning",
|
attribute_getter="temperature_warning",
|
||||||
type=Feature.Type.BinarySensor,
|
type=Feature.Type.BinarySensor,
|
||||||
icon="mdi:alert",
|
icon="mdi:alert",
|
||||||
|
category=Feature.Category.Debug,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Temperature unit",
|
id="temperature_unit",
|
||||||
|
name="Temperature unit",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="temperature_unit",
|
attribute_getter="temperature_unit",
|
||||||
attribute_setter="set_temperature_unit",
|
attribute_setter="set_temperature_unit",
|
||||||
|
@ -36,7 +36,8 @@ class TemperatureControl(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Target temperature",
|
id="target_temperature",
|
||||||
|
name="Target temperature",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="target_temperature",
|
attribute_getter="target_temperature",
|
||||||
attribute_setter="set_target_temperature",
|
attribute_setter="set_target_temperature",
|
||||||
@ -50,7 +51,8 @@ class TemperatureControl(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Temperature offset",
|
id="temperature_offset",
|
||||||
|
name="Temperature offset",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="temperature_offset",
|
attribute_getter="temperature_offset",
|
||||||
attribute_setter="set_temperature_offset",
|
attribute_setter="set_temperature_offset",
|
||||||
@ -64,7 +66,8 @@ class TemperatureControl(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"State",
|
id="state",
|
||||||
|
name="State",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="state",
|
attribute_getter="state",
|
||||||
attribute_setter="set_state",
|
attribute_setter="set_state",
|
||||||
@ -76,7 +79,8 @@ class TemperatureControl(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Mode",
|
id="mode",
|
||||||
|
name="Mode",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="mode",
|
attribute_getter="mode",
|
||||||
category=Feature.Category.Primary,
|
category=Feature.Category.Primary,
|
||||||
|
@ -25,6 +25,7 @@ class TimeModule(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device=device,
|
device=device,
|
||||||
|
id="time",
|
||||||
name="Time",
|
name="Time",
|
||||||
attribute_getter="time",
|
attribute_getter="time",
|
||||||
container=self,
|
container=self,
|
||||||
|
@ -30,19 +30,23 @@ class WaterleakSensor(SmartModule):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Water leak",
|
id="water_leak",
|
||||||
|
name="Water leak",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="status",
|
attribute_getter="status",
|
||||||
icon="mdi:water",
|
icon="mdi:water",
|
||||||
|
category=Feature.Category.Debug,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
"Water alert",
|
id="water_alert",
|
||||||
|
name="Water alert",
|
||||||
container=self,
|
container=self,
|
||||||
attribute_getter="alert",
|
attribute_getter="alert",
|
||||||
icon="mdi:water-alert",
|
icon="mdi:water-alert",
|
||||||
|
category=Feature.Category.Primary,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -225,7 +225,8 @@ class SmartDevice(Bulb, Fan, Device):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
self,
|
self,
|
||||||
"Device ID",
|
id="device_id",
|
||||||
|
name="Device ID",
|
||||||
attribute_getter="device_id",
|
attribute_getter="device_id",
|
||||||
category=Feature.Category.Debug,
|
category=Feature.Category.Debug,
|
||||||
)
|
)
|
||||||
@ -234,7 +235,8 @@ class SmartDevice(Bulb, Fan, Device):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
self,
|
self,
|
||||||
"State",
|
id="state",
|
||||||
|
name="State",
|
||||||
attribute_getter="is_on",
|
attribute_getter="is_on",
|
||||||
attribute_setter="set_state",
|
attribute_setter="set_state",
|
||||||
type=Feature.Type.Switch,
|
type=Feature.Type.Switch,
|
||||||
@ -246,7 +248,8 @@ class SmartDevice(Bulb, Fan, Device):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
self,
|
self,
|
||||||
"Signal Level",
|
id="signal_level",
|
||||||
|
name="Signal Level",
|
||||||
attribute_getter=lambda x: x._info["signal_level"],
|
attribute_getter=lambda x: x._info["signal_level"],
|
||||||
icon="mdi:signal",
|
icon="mdi:signal",
|
||||||
category=Feature.Category.Info,
|
category=Feature.Category.Info,
|
||||||
@ -257,7 +260,8 @@ class SmartDevice(Bulb, Fan, Device):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
self,
|
self,
|
||||||
"RSSI",
|
id="rssi",
|
||||||
|
name="RSSI",
|
||||||
attribute_getter=lambda x: x._info["rssi"],
|
attribute_getter=lambda x: x._info["rssi"],
|
||||||
icon="mdi:signal",
|
icon="mdi:signal",
|
||||||
category=Feature.Category.Debug,
|
category=Feature.Category.Debug,
|
||||||
@ -268,6 +272,7 @@ class SmartDevice(Bulb, Fan, Device):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device=self,
|
device=self,
|
||||||
|
id="ssid",
|
||||||
name="SSID",
|
name="SSID",
|
||||||
attribute_getter="ssid",
|
attribute_getter="ssid",
|
||||||
icon="mdi:wifi",
|
icon="mdi:wifi",
|
||||||
@ -279,11 +284,12 @@ class SmartDevice(Bulb, Fan, Device):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
self,
|
self,
|
||||||
"Overheated",
|
id="overheated",
|
||||||
|
name="Overheated",
|
||||||
attribute_getter=lambda x: x._info["overheated"],
|
attribute_getter=lambda x: x._info["overheated"],
|
||||||
icon="mdi:heat-wave",
|
icon="mdi:heat-wave",
|
||||||
type=Feature.Type.BinarySensor,
|
type=Feature.Type.BinarySensor,
|
||||||
category=Feature.Category.Debug,
|
category=Feature.Category.Info,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -293,10 +299,11 @@ class SmartDevice(Bulb, Fan, Device):
|
|||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device=self,
|
device=self,
|
||||||
|
id="on_since",
|
||||||
name="On since",
|
name="On since",
|
||||||
attribute_getter="on_since",
|
attribute_getter="on_since",
|
||||||
icon="mdi:clock",
|
icon="mdi:clock",
|
||||||
category=Feature.Category.Debug,
|
category=Feature.Category.Info,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ def dummy_feature() -> Feature:
|
|||||||
|
|
||||||
feat = Feature(
|
feat = Feature(
|
||||||
device=DummyDevice(), # type: ignore[arg-type]
|
device=DummyDevice(), # type: ignore[arg-type]
|
||||||
|
id="dummy_feature",
|
||||||
name="dummy_feature",
|
name="dummy_feature",
|
||||||
attribute_getter="dummygetter",
|
attribute_getter="dummygetter",
|
||||||
attribute_setter="dummysetter",
|
attribute_setter="dummysetter",
|
||||||
@ -47,6 +48,7 @@ def test_feature_missing_type():
|
|||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
Feature(
|
Feature(
|
||||||
device=DummyDevice(), # type: ignore[arg-type]
|
device=DummyDevice(), # type: ignore[arg-type]
|
||||||
|
id="dummy_error",
|
||||||
name="dummy error",
|
name="dummy error",
|
||||||
attribute_getter="dummygetter",
|
attribute_getter="dummygetter",
|
||||||
attribute_setter="dummysetter",
|
attribute_setter="dummysetter",
|
||||||
@ -104,6 +106,7 @@ async def test_feature_action(mocker):
|
|||||||
"""Test that setting value on button calls the setter."""
|
"""Test that setting value on button calls the setter."""
|
||||||
feat = Feature(
|
feat = Feature(
|
||||||
device=DummyDevice(), # type: ignore[arg-type]
|
device=DummyDevice(), # type: ignore[arg-type]
|
||||||
|
id="dummy_feature",
|
||||||
name="dummy_feature",
|
name="dummy_feature",
|
||||||
attribute_setter="call_action",
|
attribute_setter="call_action",
|
||||||
container=None,
|
container=None,
|
||||||
|
Loading…
Reference in New Issue
Block a user