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:
@@ -23,9 +23,9 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Set up Oasis device binary sensor entities for a config entry.
|
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.
|
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:
|
Parameters:
|
||||||
entry (OasisDeviceConfigEntry): Configuration entry for the Oasis integration containing runtime data and coordinator used to create entities.
|
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]):
|
def make_entities(new_devices: list[OasisDevice]):
|
||||||
"""
|
"""
|
||||||
Create binary sensor entity instances for each provided Oasis device using the module's descriptors.
|
Create binary sensor entity instances for each provided Oasis device using the module's descriptors.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
new_devices (list[OasisDevice]): Devices to generate entities for.
|
new_devices (list[OasisDevice]): Devices to generate entities for.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list[OasisDeviceBinarySensorEntity]: A list of binary sensor entities pairing each device with every descriptor in DESCRIPTORS.
|
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)
|
setup_platform_from_coordinator(entry, async_add_entities, make_entities)
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTORS = {
|
DESCRIPTORS = (
|
||||||
BinarySensorEntityDescription(
|
BinarySensorEntityDescription(
|
||||||
key="busy",
|
key="busy",
|
||||||
translation_key="busy",
|
translation_key="busy",
|
||||||
@@ -63,7 +63,7 @@ DESCRIPTORS = {
|
|||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
),
|
),
|
||||||
}
|
)
|
||||||
|
|
||||||
|
|
||||||
class OasisDeviceBinarySensorEntity(OasisDeviceEntity, BinarySensorEntity):
|
class OasisDeviceBinarySensorEntity(OasisDeviceEntity, BinarySensorEntity):
|
||||||
@@ -73,8 +73,8 @@ class OasisDeviceBinarySensorEntity(OasisDeviceEntity, BinarySensorEntity):
|
|||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""
|
"""
|
||||||
Indicates whether the binary sensor is currently active.
|
Indicates whether the binary sensor is currently active.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: True if the sensor is on, False otherwise.
|
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)
|
||||||
|
|||||||
@@ -29,17 +29,17 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Set up number entities for Oasis devices from a configuration entry.
|
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.
|
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]):
|
def make_entities(new_devices: list[OasisDevice]):
|
||||||
"""
|
"""
|
||||||
Create number entity instances for each provided Oasis device using the module's DESCRIPTORS.
|
Create number entity instances for each provided Oasis device using the module's DESCRIPTORS.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
new_devices (list[OasisDevice]): Devices to create entities for.
|
new_devices (list[OasisDevice]): Devices to create entities for.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list[OasisDeviceNumberEntity]: A flat list of number entities (one per descriptor for each device).
|
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)
|
setup_platform_from_coordinator(entry, async_add_entities, make_entities)
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTORS = {
|
DESCRIPTORS = (
|
||||||
NumberEntityDescription(
|
NumberEntityDescription(
|
||||||
key="ball_speed",
|
key="ball_speed",
|
||||||
translation_key="ball_speed",
|
translation_key="ball_speed",
|
||||||
@@ -69,7 +69,7 @@ DESCRIPTORS = {
|
|||||||
native_max_value=LED_SPEED_MAX,
|
native_max_value=LED_SPEED_MAX,
|
||||||
native_min_value=LED_SPEED_MIN,
|
native_min_value=LED_SPEED_MIN,
|
||||||
),
|
),
|
||||||
}
|
)
|
||||||
|
|
||||||
|
|
||||||
class OasisDeviceNumberEntity(OasisDeviceEntity, NumberEntity):
|
class OasisDeviceNumberEntity(OasisDeviceEntity, NumberEntity):
|
||||||
@@ -79,7 +79,7 @@ class OasisDeviceNumberEntity(OasisDeviceEntity, NumberEntity):
|
|||||||
def native_value(self) -> str | None:
|
def native_value(self) -> str | None:
|
||||||
"""
|
"""
|
||||||
Get the current value of the number entity from the underlying device.
|
Get the current value of the number entity from the underlying device.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
str | None: The current value as a string, or `None` if the device has no value.
|
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:
|
async def async_set_native_value(self, value: float) -> None:
|
||||||
"""
|
"""
|
||||||
Set the configured numeric value on the underlying Oasis device.
|
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.
|
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:
|
Parameters:
|
||||||
value (float): New numeric value to apply; will be converted to an integer.
|
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":
|
if self.entity_description.key == "ball_speed":
|
||||||
await self.device.async_set_ball_speed(value)
|
await self.device.async_set_ball_speed(value)
|
||||||
elif self.entity_description.key == "led_speed":
|
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)
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Set up and register sensor entities for each Oasis device in the config entry.
|
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.
|
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:
|
Parameters:
|
||||||
hass (HomeAssistant): Home Assistant core object.
|
hass (HomeAssistant): Home Assistant core object.
|
||||||
entry (OasisDeviceConfigEntry): Configuration entry containing runtime data and devices to expose.
|
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]):
|
def make_entities(new_devices: list[OasisDevice]):
|
||||||
"""
|
"""
|
||||||
Create sensor entity instances for each Oasis device and each sensor descriptor.
|
Create sensor entity instances for each Oasis device and each sensor descriptor.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
new_devices (list[OasisDevice]): Devices to create sensor entities for.
|
new_devices (list[OasisDevice]): Devices to create sensor entities for.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list[OasisDeviceSensorEntity]: A list containing one sensor entity per combination of device and descriptor from DESCRIPTORS.
|
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)
|
setup_platform_from_coordinator(entry, async_add_entities, make_entities)
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTORS = {
|
DESCRIPTORS = [
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key="download_progress",
|
key="download_progress",
|
||||||
translation_key="download_progress",
|
translation_key="download_progress",
|
||||||
@@ -68,7 +68,8 @@ DESCRIPTORS = {
|
|||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
suggested_display_precision=1,
|
suggested_display_precision=1,
|
||||||
),
|
),
|
||||||
} | {
|
]
|
||||||
|
DESCRIPTORS.extend(
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key=key,
|
key=key,
|
||||||
translation_key=key,
|
translation_key=key,
|
||||||
@@ -77,7 +78,7 @@ DESCRIPTORS = {
|
|||||||
)
|
)
|
||||||
for key in ("error", "led_color_id", "status")
|
for key in ("error", "led_color_id", "status")
|
||||||
# for key in ("error_message", "led_color_id", "status")
|
# for key in ("error_message", "led_color_id", "status")
|
||||||
}
|
)
|
||||||
|
|
||||||
|
|
||||||
class OasisDeviceSensorEntity(OasisDeviceEntity, SensorEntity):
|
class OasisDeviceSensorEntity(OasisDeviceEntity, SensorEntity):
|
||||||
@@ -87,8 +88,8 @@ class OasisDeviceSensorEntity(OasisDeviceEntity, SensorEntity):
|
|||||||
def native_value(self) -> str | None:
|
def native_value(self) -> str | None:
|
||||||
"""
|
"""
|
||||||
Provide the current sensor value from the underlying device.
|
Provide the current sensor value from the underlying device.
|
||||||
|
|
||||||
Returns:
|
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`.
|
`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)
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Set up Oasis device switch entities for a config entry.
|
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.
|
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:
|
Parameters:
|
||||||
hass: Home Assistant core instance.
|
hass: Home Assistant core instance.
|
||||||
entry: OasisDeviceConfigEntry containing runtime data and the devices to expose as switch entities.
|
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]):
|
def make_entities(new_devices: list[OasisDevice]):
|
||||||
"""
|
"""
|
||||||
Create OasisDeviceSwitchEntity instances for each device and descriptor.
|
Create OasisDeviceSwitchEntity instances for each device and descriptor.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
new_devices (list[OasisDevice]): Devices to wrap as switch entities.
|
new_devices (list[OasisDevice]): Devices to wrap as switch entities.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list[OasisDeviceSwitchEntity]: A list containing one switch entity per device per descriptor from DESCRIPTORS.
|
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)
|
setup_platform_from_coordinator(entry, async_add_entities, make_entities)
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTORS = {
|
DESCRIPTORS = (
|
||||||
SwitchEntityDescription(
|
SwitchEntityDescription(
|
||||||
key="auto_clean",
|
key="auto_clean",
|
||||||
translation_key="auto_clean",
|
translation_key="auto_clean",
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
),
|
),
|
||||||
}
|
)
|
||||||
|
|
||||||
|
|
||||||
class OasisDeviceSwitchEntity(OasisDeviceEntity, SwitchEntity):
|
class OasisDeviceSwitchEntity(OasisDeviceEntity, SwitchEntity):
|
||||||
@@ -65,7 +65,7 @@ class OasisDeviceSwitchEntity(OasisDeviceEntity, SwitchEntity):
|
|||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""
|
"""
|
||||||
Determine whether the switch entity is currently on.
|
Determine whether the switch entity is currently on.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: `True` if the underlying device attribute named by this entity's description key is truthy, `False` otherwise.
|
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:
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
"""
|
"""
|
||||||
Disable the device's automatic cleaning mode.
|
Disable the device's automatic cleaning mode.
|
||||||
|
|
||||||
Sets the device's auto_clean setting to off.
|
Sets the device's auto_clean setting to off.
|
||||||
"""
|
"""
|
||||||
await self.device.async_set_auto_clean(False)
|
await self.device.async_set_auto_clean(False)
|
||||||
@@ -83,4 +83,4 @@ class OasisDeviceSwitchEntity(OasisDeviceEntity, SwitchEntity):
|
|||||||
"""
|
"""
|
||||||
Enable the device's auto-clean feature.
|
Enable the device's auto-clean feature.
|
||||||
"""
|
"""
|
||||||
await self.device.async_set_auto_clean(True)
|
await self.device.async_set_auto_clean(True)
|
||||||
|
|||||||
Reference in New Issue
Block a user