Implement feature categories (#846)

Initial implementation for feature categories to help downstreams and
our cli tool to categorize the data for more user-friendly manner. As
more and more information is being exposed through the generic features
interface, it is necessary to give some hints to downstreams about how
might want to present the information to users.

This is not a 1:1 mapping to the homeassistant's mental model, and it
will be necessary to fine-tune homeassistant-specific parameters by
other means to polish the presentation.
This commit is contained in:
Teemu R
2024-04-23 19:20:12 +02:00
committed by GitHub
parent aa969ef020
commit b860c32d5f
12 changed files with 123 additions and 21 deletions

View File

@@ -32,6 +32,7 @@ class Brightness(SmartModule):
minimum_value=BRIGHTNESS_MIN,
maximum_value=BRIGHTNESS_MAX,
type=FeatureType.Number,
category=Feature.Category.Primary,
)
)

View File

@@ -33,6 +33,7 @@ class ColorTemperatureModule(SmartModule):
attribute_getter="color_temp",
attribute_setter="set_color_temp",
range_getter="valid_temperature_range",
category=Feature.Category.Primary,
)
)

View File

@@ -30,6 +30,7 @@ class FanModule(SmartModule):
type=FeatureType.Number,
minimum_value=1,
maximum_value=4,
category=Feature.Category.Primary,
)
)
self._add_feature(

View File

@@ -28,6 +28,7 @@ class LedModule(SmartModule):
attribute_getter="led",
attribute_setter="set_led",
type=FeatureType.Switch,
category=Feature.Category.Config,
)
)

View File

@@ -25,6 +25,7 @@ class ReportModule(SmartModule):
"Report interval",
container=self,
attribute_getter="report_interval",
category=Feature.Category.Debug,
)
)

View File

@@ -28,6 +28,7 @@ class TimeModule(SmartModule):
name="Time",
attribute_getter="time",
container=self,
category=Feature.Category.Debug,
)
)

View File

@@ -176,7 +176,14 @@ class SmartDevice(Device):
async def _initialize_features(self):
"""Initialize device features."""
self._add_feature(Feature(self, "Device ID", attribute_getter="device_id"))
self._add_feature(
Feature(
self,
"Device ID",
attribute_getter="device_id",
category=Feature.Category.Debug,
)
)
if "device_on" in self._info:
self._add_feature(
Feature(
@@ -185,6 +192,7 @@ class SmartDevice(Device):
attribute_getter="is_on",
attribute_setter="set_state",
type=FeatureType.Switch,
category=Feature.Category.Primary,
)
)
@@ -195,6 +203,7 @@ class SmartDevice(Device):
"Signal Level",
attribute_getter=lambda x: x._info["signal_level"],
icon="mdi:signal",
category=Feature.Category.Info,
)
)
@@ -205,13 +214,18 @@ class SmartDevice(Device):
"RSSI",
attribute_getter=lambda x: x._info["rssi"],
icon="mdi:signal",
category=Feature.Category.Debug,
)
)
if "ssid" in self._info:
self._add_feature(
Feature(
device=self, name="SSID", attribute_getter="ssid", icon="mdi:wifi"
device=self,
name="SSID",
attribute_getter="ssid",
icon="mdi:wifi",
category=Feature.Category.Debug,
)
)
@@ -223,6 +237,7 @@ class SmartDevice(Device):
attribute_getter=lambda x: x._info["overheated"],
icon="mdi:heat-wave",
type=FeatureType.BinarySensor,
category=Feature.Category.Debug,
)
)
@@ -235,6 +250,7 @@ class SmartDevice(Device):
name="On since",
attribute_getter="on_since",
icon="mdi:clock",
category=Feature.Category.Debug,
)
)