1
0
mirror of https://github.com/natekspencer/hacs-oasis_mini.git synced 2025-12-06 18:44:14 -05:00

Use tuples instead of sets for descriptors

This commit is contained in:
Nathan Spencer
2025-11-24 01:04:56 +00:00
parent aa7abc2174
commit a6ecd740be
4 changed files with 36 additions and 35 deletions

View File

@@ -23,9 +23,9 @@ async def async_setup_entry(
) -> None:
"""
Set up Oasis device binary sensor entities for a config entry.
Registers a factory that creates an OasisDeviceBinarySensorEntity for each device and descriptor defined in DESCRIPTORS, and forwards those entities to Home Assistant via the provided add-entities callback.
Parameters:
entry (OasisDeviceConfigEntry): Configuration entry for the Oasis integration containing runtime data and coordinator used to create entities.
"""
@@ -33,10 +33,10 @@ async def async_setup_entry(
def make_entities(new_devices: list[OasisDevice]):
"""
Create binary sensor entity instances for each provided Oasis device using the module's descriptors.
Parameters:
new_devices (list[OasisDevice]): Devices to generate entities for.
Returns:
list[OasisDeviceBinarySensorEntity]: A list of binary sensor entities pairing each device with every descriptor in DESCRIPTORS.
"""
@@ -49,7 +49,7 @@ async def async_setup_entry(
setup_platform_from_coordinator(entry, async_add_entities, make_entities)
DESCRIPTORS = {
DESCRIPTORS = (
BinarySensorEntityDescription(
key="busy",
translation_key="busy",
@@ -63,7 +63,7 @@ DESCRIPTORS = {
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
}
)
class OasisDeviceBinarySensorEntity(OasisDeviceEntity, BinarySensorEntity):
@@ -73,8 +73,8 @@ class OasisDeviceBinarySensorEntity(OasisDeviceEntity, BinarySensorEntity):
def is_on(self) -> bool:
"""
Indicates whether the binary sensor is currently active.
Returns:
bool: True if the sensor is on, False otherwise.
"""
return getattr(self.device, self.entity_description.key)
return getattr(self.device, self.entity_description.key)

View File

@@ -29,17 +29,17 @@ async def async_setup_entry(
) -> None:
"""
Set up number entities for Oasis devices from a configuration entry.
Creates number entities for each discovered Oasis device and each descriptor in DESCRIPTORS, then registers those entities with the platform coordinator so they are added to Home Assistant.
"""
def make_entities(new_devices: list[OasisDevice]):
"""
Create number entity instances for each provided Oasis device using the module's DESCRIPTORS.
Parameters:
new_devices (list[OasisDevice]): Devices to create entities for.
Returns:
list[OasisDeviceNumberEntity]: A flat list of number entities (one per descriptor for each device).
"""
@@ -52,7 +52,7 @@ async def async_setup_entry(
setup_platform_from_coordinator(entry, async_add_entities, make_entities)
DESCRIPTORS = {
DESCRIPTORS = (
NumberEntityDescription(
key="ball_speed",
translation_key="ball_speed",
@@ -69,7 +69,7 @@ DESCRIPTORS = {
native_max_value=LED_SPEED_MAX,
native_min_value=LED_SPEED_MIN,
),
}
)
class OasisDeviceNumberEntity(OasisDeviceEntity, NumberEntity):
@@ -79,7 +79,7 @@ class OasisDeviceNumberEntity(OasisDeviceEntity, NumberEntity):
def native_value(self) -> str | None:
"""
Get the current value of the number entity from the underlying device.
Returns:
str | None: The current value as a string, or `None` if the device has no value.
"""
@@ -88,9 +88,9 @@ class OasisDeviceNumberEntity(OasisDeviceEntity, NumberEntity):
async def async_set_native_value(self, value: float) -> None:
"""
Set the configured numeric value on the underlying Oasis device.
The provided value is converted to an integer and applied to the device property indicated by this entity's description key: if the key is "ball_speed" the device's ball speed is updated; if the key is "led_speed" the device's LED speed is updated.
Parameters:
value (float): New numeric value to apply; will be converted to an integer.
"""
@@ -98,4 +98,4 @@ class OasisDeviceNumberEntity(OasisDeviceEntity, NumberEntity):
if self.entity_description.key == "ball_speed":
await self.device.async_set_ball_speed(value)
elif self.entity_description.key == "led_speed":
await self.device.async_set_led(led_speed=value)
await self.device.async_set_led(led_speed=value)

View File

@@ -23,9 +23,9 @@ async def async_setup_entry(
) -> None:
"""
Set up and register sensor entities for each Oasis device in the config entry.
Creates sensor entities for every Oasis device available on the provided config entry and adds them to Home Assistant via the provided add-entities callback.
Parameters:
hass (HomeAssistant): Home Assistant core object.
entry (OasisDeviceConfigEntry): Configuration entry containing runtime data and devices to expose.
@@ -35,10 +35,10 @@ async def async_setup_entry(
def make_entities(new_devices: list[OasisDevice]):
"""
Create sensor entity instances for each Oasis device and each sensor descriptor.
Parameters:
new_devices (list[OasisDevice]): Devices to create sensor entities for.
Returns:
list[OasisDeviceSensorEntity]: A list containing one sensor entity per combination of device and descriptor from DESCRIPTORS.
"""
@@ -51,7 +51,7 @@ async def async_setup_entry(
setup_platform_from_coordinator(entry, async_add_entities, make_entities)
DESCRIPTORS = {
DESCRIPTORS = [
SensorEntityDescription(
key="download_progress",
translation_key="download_progress",
@@ -68,7 +68,8 @@ DESCRIPTORS = {
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=1,
),
} | {
]
DESCRIPTORS.extend(
SensorEntityDescription(
key=key,
translation_key=key,
@@ -77,7 +78,7 @@ DESCRIPTORS = {
)
for key in ("error", "led_color_id", "status")
# for key in ("error_message", "led_color_id", "status")
}
)
class OasisDeviceSensorEntity(OasisDeviceEntity, SensorEntity):
@@ -87,8 +88,8 @@ class OasisDeviceSensorEntity(OasisDeviceEntity, SensorEntity):
def native_value(self) -> str | None:
"""
Provide the current sensor value from the underlying device.
Returns:
`str` with the sensor's current value, or `None` if the attribute is not present or has no value. The value is taken from the device attribute named by the entity description's `key`.
"""
return getattr(self.device, self.entity_description.key)
return getattr(self.device, self.entity_description.key)

View File

@@ -21,9 +21,9 @@ async def async_setup_entry(
) -> None:
"""
Set up Oasis device switch entities for a config entry.
Creates an OasisDeviceSwitchEntity for each OasisDevice associated with the given config entry (one entity per descriptor in DESCRIPTORS) and registers them with Home Assistant via the coordinator helper.
Parameters:
hass: Home Assistant core instance.
entry: OasisDeviceConfigEntry containing runtime data and the devices to expose as switch entities.
@@ -33,10 +33,10 @@ async def async_setup_entry(
def make_entities(new_devices: list[OasisDevice]):
"""
Create OasisDeviceSwitchEntity instances for each device and descriptor.
Parameters:
new_devices (list[OasisDevice]): Devices to wrap as switch entities.
Returns:
list[OasisDeviceSwitchEntity]: A list containing one switch entity per device per descriptor from DESCRIPTORS.
"""
@@ -49,13 +49,13 @@ async def async_setup_entry(
setup_platform_from_coordinator(entry, async_add_entities, make_entities)
DESCRIPTORS = {
DESCRIPTORS = (
SwitchEntityDescription(
key="auto_clean",
translation_key="auto_clean",
entity_category=EntityCategory.CONFIG,
),
}
)
class OasisDeviceSwitchEntity(OasisDeviceEntity, SwitchEntity):
@@ -65,7 +65,7 @@ class OasisDeviceSwitchEntity(OasisDeviceEntity, SwitchEntity):
def is_on(self) -> bool:
"""
Determine whether the switch entity is currently on.
Returns:
bool: `True` if the underlying device attribute named by this entity's description key is truthy, `False` otherwise.
"""
@@ -74,7 +74,7 @@ class OasisDeviceSwitchEntity(OasisDeviceEntity, SwitchEntity):
async def async_turn_off(self, **kwargs: Any) -> None:
"""
Disable the device's automatic cleaning mode.
Sets the device's auto_clean setting to off.
"""
await self.device.async_set_auto_clean(False)
@@ -83,4 +83,4 @@ class OasisDeviceSwitchEntity(OasisDeviceEntity, SwitchEntity):
"""
Enable the device's auto-clean feature.
"""
await self.device.async_set_auto_clean(True)
await self.device.async_set_auto_clean(True)