mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Standardize zha attribute member name (#102182)
* Correct missed translation * Standardize on _attribute for zha
This commit is contained in:
parent
dae742fba0
commit
90687e9794
@ -72,7 +72,7 @@ async def async_setup_entry(
|
||||
class BinarySensor(ZhaEntity, BinarySensorEntity):
|
||||
"""ZHA BinarySensor."""
|
||||
|
||||
SENSOR_ATTR: str | None = None
|
||||
_attribute_name: str
|
||||
|
||||
def __init__(self, unique_id, zha_device, cluster_handlers, **kwargs):
|
||||
"""Initialize the ZHA binary sensor."""
|
||||
@ -89,7 +89,7 @@ class BinarySensor(ZhaEntity, BinarySensorEntity):
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return True if the switch is on based on the state machine."""
|
||||
raw_state = self._cluster_handler.cluster.get(self.SENSOR_ATTR)
|
||||
raw_state = self._cluster_handler.cluster.get(self._attribute_name)
|
||||
if raw_state is None:
|
||||
return False
|
||||
return self.parse(raw_state)
|
||||
@ -109,7 +109,7 @@ class BinarySensor(ZhaEntity, BinarySensorEntity):
|
||||
class Accelerometer(BinarySensor):
|
||||
"""ZHA BinarySensor."""
|
||||
|
||||
SENSOR_ATTR = "acceleration"
|
||||
_attribute_name = "acceleration"
|
||||
_attr_device_class: BinarySensorDeviceClass = BinarySensorDeviceClass.MOVING
|
||||
_attr_translation_key: str = "accelerometer"
|
||||
|
||||
@ -118,7 +118,7 @@ class Accelerometer(BinarySensor):
|
||||
class Occupancy(BinarySensor):
|
||||
"""ZHA BinarySensor."""
|
||||
|
||||
SENSOR_ATTR = "occupancy"
|
||||
_attribute_name = "occupancy"
|
||||
_attr_device_class: BinarySensorDeviceClass = BinarySensorDeviceClass.OCCUPANCY
|
||||
|
||||
|
||||
@ -133,7 +133,7 @@ class HueOccupancy(Occupancy):
|
||||
class Opening(BinarySensor):
|
||||
"""ZHA OnOff BinarySensor."""
|
||||
|
||||
SENSOR_ATTR = "on_off"
|
||||
_attribute_name = "on_off"
|
||||
_attr_device_class: BinarySensorDeviceClass = BinarySensorDeviceClass.OPENING
|
||||
|
||||
# Client/out cluster attributes aren't stored in the zigpy database, but are properly stored in the runtime cache.
|
||||
@ -142,7 +142,7 @@ class Opening(BinarySensor):
|
||||
def async_restore_last_state(self, last_state):
|
||||
"""Restore previous state to zigpy cache."""
|
||||
self._cluster_handler.cluster.update_attribute(
|
||||
OnOff.attributes_by_name[self.SENSOR_ATTR].id,
|
||||
OnOff.attributes_by_name[self._attribute_name].id,
|
||||
t.Bool.true if last_state.state == STATE_ON else t.Bool.false,
|
||||
)
|
||||
|
||||
@ -151,7 +151,7 @@ class Opening(BinarySensor):
|
||||
class BinaryInput(BinarySensor):
|
||||
"""ZHA BinarySensor."""
|
||||
|
||||
SENSOR_ATTR = "present_value"
|
||||
_attribute_name = "present_value"
|
||||
_attr_translation_key: str = "binary_input"
|
||||
|
||||
|
||||
@ -177,7 +177,7 @@ class Motion(Opening):
|
||||
class IASZone(BinarySensor):
|
||||
"""ZHA IAS BinarySensor."""
|
||||
|
||||
SENSOR_ATTR = "zone_status"
|
||||
_attribute_name = "zone_status"
|
||||
|
||||
@property
|
||||
def translation_key(self) -> str | None:
|
||||
@ -225,7 +225,7 @@ class IASZone(BinarySensor):
|
||||
migrated_state = IasZone.ZoneStatus(0)
|
||||
|
||||
self._cluster_handler.cluster.update_attribute(
|
||||
IasZone.attributes_by_name[self.SENSOR_ATTR].id, migrated_state
|
||||
IasZone.attributes_by_name[self._attribute_name].id, migrated_state
|
||||
)
|
||||
|
||||
|
||||
@ -233,7 +233,7 @@ class IASZone(BinarySensor):
|
||||
class SinopeLeakStatus(BinarySensor):
|
||||
"""Sinope water leak sensor."""
|
||||
|
||||
SENSOR_ATTR = "leak_status"
|
||||
_attribute_name = "leak_status"
|
||||
_attr_device_class = BinarySensorDeviceClass.MOISTURE
|
||||
|
||||
|
||||
@ -246,7 +246,7 @@ class SinopeLeakStatus(BinarySensor):
|
||||
class FrostLock(BinarySensor):
|
||||
"""ZHA BinarySensor."""
|
||||
|
||||
SENSOR_ATTR = "frost_lock"
|
||||
_attribute_name = "frost_lock"
|
||||
_unique_id_suffix = "frost_lock"
|
||||
_attr_device_class: BinarySensorDeviceClass = BinarySensorDeviceClass.LOCK
|
||||
_attr_translation_key: str = "frost_lock"
|
||||
@ -256,7 +256,7 @@ class FrostLock(BinarySensor):
|
||||
class ReplaceFilter(BinarySensor):
|
||||
"""ZHA BinarySensor."""
|
||||
|
||||
SENSOR_ATTR = "replace_filter"
|
||||
_attribute_name = "replace_filter"
|
||||
_unique_id_suffix = "replace_filter"
|
||||
_attr_device_class: BinarySensorDeviceClass = BinarySensorDeviceClass.PROBLEM
|
||||
_attr_entity_category: EntityCategory = EntityCategory.DIAGNOSTIC
|
||||
@ -267,7 +267,7 @@ class ReplaceFilter(BinarySensor):
|
||||
class AqaraPetFeederErrorDetected(BinarySensor):
|
||||
"""ZHA aqara pet feeder error detected binary sensor."""
|
||||
|
||||
SENSOR_ATTR = "error_detected"
|
||||
_attribute_name = "error_detected"
|
||||
_unique_id_suffix = "error_detected"
|
||||
_attr_device_class: BinarySensorDeviceClass = BinarySensorDeviceClass.PROBLEM
|
||||
|
||||
@ -279,7 +279,7 @@ class AqaraPetFeederErrorDetected(BinarySensor):
|
||||
class XiaomiPlugConsumerConnected(BinarySensor):
|
||||
"""ZHA Xiaomi plug consumer connected binary sensor."""
|
||||
|
||||
SENSOR_ATTR = "consumer_connected"
|
||||
_attribute_name = "consumer_connected"
|
||||
_unique_id_suffix = "consumer_connected"
|
||||
_attr_device_class: BinarySensorDeviceClass = BinarySensorDeviceClass.PLUG
|
||||
_attr_translation_key: str = "consumer_connected"
|
||||
@ -289,7 +289,7 @@ class XiaomiPlugConsumerConnected(BinarySensor):
|
||||
class AqaraThermostatWindowOpen(BinarySensor):
|
||||
"""ZHA Aqara thermostat window open binary sensor."""
|
||||
|
||||
SENSOR_ATTR = "window_open"
|
||||
_attribute_name = "window_open"
|
||||
_unique_id_suffix = "window_open"
|
||||
_attr_device_class: BinarySensorDeviceClass = BinarySensorDeviceClass.WINDOW
|
||||
|
||||
@ -298,7 +298,7 @@ class AqaraThermostatWindowOpen(BinarySensor):
|
||||
class AqaraThermostatValveAlarm(BinarySensor):
|
||||
"""ZHA Aqara thermostat valve alarm binary sensor."""
|
||||
|
||||
SENSOR_ATTR = "valve_alarm"
|
||||
_attribute_name = "valve_alarm"
|
||||
_unique_id_suffix = "valve_alarm"
|
||||
_attr_device_class: BinarySensorDeviceClass = BinarySensorDeviceClass.PROBLEM
|
||||
_attr_translation_key: str = "valve_alarm"
|
||||
@ -310,7 +310,7 @@ class AqaraThermostatValveAlarm(BinarySensor):
|
||||
class AqaraThermostatCalibrated(BinarySensor):
|
||||
"""ZHA Aqara thermostat calibrated binary sensor."""
|
||||
|
||||
SENSOR_ATTR = "calibrated"
|
||||
_attribute_name = "calibrated"
|
||||
_unique_id_suffix = "calibrated"
|
||||
_attr_entity_category: EntityCategory = EntityCategory.DIAGNOSTIC
|
||||
_attr_translation_key: str = "calibrated"
|
||||
@ -322,7 +322,7 @@ class AqaraThermostatCalibrated(BinarySensor):
|
||||
class AqaraThermostatExternalSensor(BinarySensor):
|
||||
"""ZHA Aqara thermostat external sensor binary sensor."""
|
||||
|
||||
SENSOR_ATTR = "sensor"
|
||||
_attribute_name = "sensor"
|
||||
_unique_id_suffix = "sensor"
|
||||
_attr_entity_category: EntityCategory = EntityCategory.DIAGNOSTIC
|
||||
_attr_translation_key: str = "external_sensor"
|
||||
@ -332,7 +332,7 @@ class AqaraThermostatExternalSensor(BinarySensor):
|
||||
class AqaraLinkageAlarmState(BinarySensor):
|
||||
"""ZHA Aqara linkage alarm state binary sensor."""
|
||||
|
||||
SENSOR_ATTR = "linkage_alarm_state"
|
||||
_attribute_name = "linkage_alarm_state"
|
||||
_unique_id_suffix = "linkage_alarm_state"
|
||||
_attr_device_class: BinarySensorDeviceClass = BinarySensorDeviceClass.SMOKE
|
||||
_attr_translation_key: str = "linkage_alarm_state"
|
||||
|
@ -381,7 +381,7 @@ class ZHANumberConfigurationEntity(ZhaEntity, NumberEntity):
|
||||
_attr_entity_category = EntityCategory.CONFIG
|
||||
_attr_native_step: float = 1.0
|
||||
_attr_multiplier: float = 1
|
||||
_zcl_attribute: str
|
||||
_attribute_name: str
|
||||
|
||||
@classmethod
|
||||
def create_entity(
|
||||
@ -397,13 +397,13 @@ class ZHANumberConfigurationEntity(ZhaEntity, NumberEntity):
|
||||
"""
|
||||
cluster_handler = cluster_handlers[0]
|
||||
if (
|
||||
cls._zcl_attribute in cluster_handler.cluster.unsupported_attributes
|
||||
or cls._zcl_attribute not in cluster_handler.cluster.attributes_by_name
|
||||
or cluster_handler.cluster.get(cls._zcl_attribute) is None
|
||||
cls._attribute_name in cluster_handler.cluster.unsupported_attributes
|
||||
or cls._attribute_name not in cluster_handler.cluster.attributes_by_name
|
||||
or cluster_handler.cluster.get(cls._attribute_name) is None
|
||||
):
|
||||
_LOGGER.debug(
|
||||
"%s is not supported - skipping %s entity creation",
|
||||
cls._zcl_attribute,
|
||||
cls._attribute_name,
|
||||
cls.__name__,
|
||||
)
|
||||
return None
|
||||
@ -425,14 +425,14 @@ class ZHANumberConfigurationEntity(ZhaEntity, NumberEntity):
|
||||
def native_value(self) -> float:
|
||||
"""Return the current value."""
|
||||
return (
|
||||
self._cluster_handler.cluster.get(self._zcl_attribute)
|
||||
self._cluster_handler.cluster.get(self._attribute_name)
|
||||
* self._attr_multiplier
|
||||
)
|
||||
|
||||
async def async_set_native_value(self, value: float) -> None:
|
||||
"""Update the current value from HA."""
|
||||
await self._cluster_handler.write_attributes_safe(
|
||||
{self._zcl_attribute: int(value / self._attr_multiplier)}
|
||||
{self._attribute_name: int(value / self._attr_multiplier)}
|
||||
)
|
||||
self.async_write_ha_state()
|
||||
|
||||
@ -442,7 +442,7 @@ class ZHANumberConfigurationEntity(ZhaEntity, NumberEntity):
|
||||
_LOGGER.debug("polling current state")
|
||||
if self._cluster_handler:
|
||||
value = await self._cluster_handler.get_attribute_value(
|
||||
self._zcl_attribute, from_cache=False
|
||||
self._attribute_name, from_cache=False
|
||||
)
|
||||
_LOGGER.debug("read value=%s", value)
|
||||
|
||||
@ -458,7 +458,7 @@ class AqaraMotionDetectionInterval(ZHANumberConfigurationEntity):
|
||||
_unique_id_suffix = "detection_interval"
|
||||
_attr_native_min_value: float = 2
|
||||
_attr_native_max_value: float = 65535
|
||||
_zcl_attribute: str = "detection_interval"
|
||||
_attribute_name = "detection_interval"
|
||||
_attr_translation_key: str = "detection_interval"
|
||||
|
||||
|
||||
@ -470,7 +470,7 @@ class OnOffTransitionTimeConfigurationEntity(ZHANumberConfigurationEntity):
|
||||
_unique_id_suffix = "on_off_transition_time"
|
||||
_attr_native_min_value: float = 0x0000
|
||||
_attr_native_max_value: float = 0xFFFF
|
||||
_zcl_attribute: str = "on_off_transition_time"
|
||||
_attribute_name = "on_off_transition_time"
|
||||
_attr_translation_key: str = "on_off_transition_time"
|
||||
|
||||
|
||||
@ -482,7 +482,7 @@ class OnLevelConfigurationEntity(ZHANumberConfigurationEntity):
|
||||
_unique_id_suffix = "on_level"
|
||||
_attr_native_min_value: float = 0x00
|
||||
_attr_native_max_value: float = 0xFF
|
||||
_zcl_attribute: str = "on_level"
|
||||
_attribute_name = "on_level"
|
||||
_attr_translation_key: str = "on_level"
|
||||
|
||||
|
||||
@ -494,7 +494,7 @@ class OnTransitionTimeConfigurationEntity(ZHANumberConfigurationEntity):
|
||||
_unique_id_suffix = "on_transition_time"
|
||||
_attr_native_min_value: float = 0x0000
|
||||
_attr_native_max_value: float = 0xFFFE
|
||||
_zcl_attribute: str = "on_transition_time"
|
||||
_attribute_name = "on_transition_time"
|
||||
_attr_translation_key: str = "on_transition_time"
|
||||
|
||||
|
||||
@ -506,7 +506,7 @@ class OffTransitionTimeConfigurationEntity(ZHANumberConfigurationEntity):
|
||||
_unique_id_suffix = "off_transition_time"
|
||||
_attr_native_min_value: float = 0x0000
|
||||
_attr_native_max_value: float = 0xFFFE
|
||||
_zcl_attribute: str = "off_transition_time"
|
||||
_attribute_name = "off_transition_time"
|
||||
_attr_translation_key: str = "off_transition_time"
|
||||
|
||||
|
||||
@ -518,7 +518,7 @@ class DefaultMoveRateConfigurationEntity(ZHANumberConfigurationEntity):
|
||||
_unique_id_suffix = "default_move_rate"
|
||||
_attr_native_min_value: float = 0x00
|
||||
_attr_native_max_value: float = 0xFE
|
||||
_zcl_attribute: str = "default_move_rate"
|
||||
_attribute_name = "default_move_rate"
|
||||
_attr_translation_key: str = "default_move_rate"
|
||||
|
||||
|
||||
@ -530,7 +530,7 @@ class StartUpCurrentLevelConfigurationEntity(ZHANumberConfigurationEntity):
|
||||
_unique_id_suffix = "start_up_current_level"
|
||||
_attr_native_min_value: float = 0x00
|
||||
_attr_native_max_value: float = 0xFF
|
||||
_zcl_attribute: str = "start_up_current_level"
|
||||
_attribute_name = "start_up_current_level"
|
||||
_attr_translation_key: str = "start_up_current_level"
|
||||
|
||||
|
||||
@ -542,7 +542,7 @@ class StartUpColorTemperatureConfigurationEntity(ZHANumberConfigurationEntity):
|
||||
_unique_id_suffix = "start_up_color_temperature"
|
||||
_attr_native_min_value: float = 153
|
||||
_attr_native_max_value: float = 500
|
||||
_zcl_attribute: str = "start_up_color_temperature"
|
||||
_attribute_name = "start_up_color_temperature"
|
||||
_attr_translation_key: str = "start_up_color_temperature"
|
||||
|
||||
def __init__(
|
||||
@ -575,7 +575,7 @@ class TimerDurationMinutes(ZHANumberConfigurationEntity):
|
||||
_attr_native_min_value: float = 0x00
|
||||
_attr_native_max_value: float = 0x257
|
||||
_attr_native_unit_of_measurement: str | None = UNITS[72]
|
||||
_zcl_attribute: str = "timer_duration"
|
||||
_attribute_name = "timer_duration"
|
||||
_attr_translation_key: str = "timer_duration"
|
||||
|
||||
|
||||
@ -590,7 +590,7 @@ class FilterLifeTime(ZHANumberConfigurationEntity):
|
||||
_attr_native_min_value: float = 0x00
|
||||
_attr_native_max_value: float = 0xFFFFFFFF
|
||||
_attr_native_unit_of_measurement: str | None = UNITS[72]
|
||||
_zcl_attribute: str = "filter_life_time"
|
||||
_attribute_name = "filter_life_time"
|
||||
_attr_translation_key: str = "filter_life_time"
|
||||
|
||||
|
||||
@ -606,7 +606,7 @@ class TiRouterTransmitPower(ZHANumberConfigurationEntity):
|
||||
_unique_id_suffix = "transmit_power"
|
||||
_attr_native_min_value: float = -20
|
||||
_attr_native_max_value: float = 20
|
||||
_zcl_attribute: str = "transmit_power"
|
||||
_attribute_name = "transmit_power"
|
||||
_attr_translation_key: str = "transmit_power"
|
||||
|
||||
|
||||
@ -620,7 +620,7 @@ class InovelliRemoteDimmingUpSpeed(ZHANumberConfigurationEntity):
|
||||
_attr_icon: str = ICONS[3]
|
||||
_attr_native_min_value: float = 0
|
||||
_attr_native_max_value: float = 126
|
||||
_zcl_attribute: str = "dimming_speed_up_remote"
|
||||
_attribute_name = "dimming_speed_up_remote"
|
||||
_attr_translation_key: str = "dimming_speed_up_remote"
|
||||
|
||||
|
||||
@ -634,7 +634,7 @@ class InovelliButtonDelay(ZHANumberConfigurationEntity):
|
||||
_attr_icon: str = ICONS[3]
|
||||
_attr_native_min_value: float = 0
|
||||
_attr_native_max_value: float = 9
|
||||
_zcl_attribute: str = "button_delay"
|
||||
_attribute_name = "button_delay"
|
||||
_attr_translation_key: str = "button_delay"
|
||||
|
||||
|
||||
@ -648,7 +648,7 @@ class InovelliLocalDimmingUpSpeed(ZHANumberConfigurationEntity):
|
||||
_attr_icon: str = ICONS[3]
|
||||
_attr_native_min_value: float = 0
|
||||
_attr_native_max_value: float = 127
|
||||
_zcl_attribute: str = "dimming_speed_up_local"
|
||||
_attribute_name = "dimming_speed_up_local"
|
||||
_attr_translation_key: str = "dimming_speed_up_local"
|
||||
|
||||
|
||||
@ -662,11 +662,9 @@ class InovelliLocalRampRateOffToOn(ZHANumberConfigurationEntity):
|
||||
_attr_icon: str = ICONS[3]
|
||||
_attr_native_min_value: float = 0
|
||||
_attr_native_max_value: float = 127
|
||||
_zcl_attribute: str = "ramp_rate_off_to_on_local"
|
||||
_attribute_name = "ramp_rate_off_to_on_local"
|
||||
_attr_translation_key: str = "ramp_rate_off_to_on_local"
|
||||
|
||||
_attr_name: str = "Local ramp rate off to on"
|
||||
|
||||
|
||||
@CONFIG_DIAGNOSTIC_MATCH(cluster_handler_names=CLUSTER_HANDLER_INOVELLI)
|
||||
# pylint: disable-next=hass-invalid-inheritance # needs fixing
|
||||
@ -678,7 +676,7 @@ class InovelliRemoteDimmingSpeedOffToOn(ZHANumberConfigurationEntity):
|
||||
_attr_icon: str = ICONS[3]
|
||||
_attr_native_min_value: float = 0
|
||||
_attr_native_max_value: float = 127
|
||||
_zcl_attribute: str = "ramp_rate_off_to_on_remote"
|
||||
_attribute_name = "ramp_rate_off_to_on_remote"
|
||||
_attr_translation_key: str = "ramp_rate_off_to_on_remote"
|
||||
|
||||
|
||||
@ -692,7 +690,7 @@ class InovelliRemoteDimmingDownSpeed(ZHANumberConfigurationEntity):
|
||||
_attr_icon: str = ICONS[3]
|
||||
_attr_native_min_value: float = 0
|
||||
_attr_native_max_value: float = 127
|
||||
_zcl_attribute: str = "dimming_speed_down_remote"
|
||||
_attribute_name = "dimming_speed_down_remote"
|
||||
_attr_translation_key: str = "dimming_speed_down_remote"
|
||||
|
||||
|
||||
@ -706,7 +704,7 @@ class InovelliLocalDimmingDownSpeed(ZHANumberConfigurationEntity):
|
||||
_attr_icon: str = ICONS[3]
|
||||
_attr_native_min_value: float = 0
|
||||
_attr_native_max_value: float = 127
|
||||
_zcl_attribute: str = "dimming_speed_down_local"
|
||||
_attribute_name = "dimming_speed_down_local"
|
||||
_attr_translation_key: str = "dimming_speed_down_local"
|
||||
|
||||
|
||||
@ -720,7 +718,7 @@ class InovelliLocalRampRateOnToOff(ZHANumberConfigurationEntity):
|
||||
_attr_icon: str = ICONS[3]
|
||||
_attr_native_min_value: float = 0
|
||||
_attr_native_max_value: float = 127
|
||||
_zcl_attribute: str = "ramp_rate_on_to_off_local"
|
||||
_attribute_name = "ramp_rate_on_to_off_local"
|
||||
_attr_translation_key: str = "ramp_rate_on_to_off_local"
|
||||
|
||||
|
||||
@ -734,7 +732,7 @@ class InovelliRemoteDimmingSpeedOnToOff(ZHANumberConfigurationEntity):
|
||||
_attr_icon: str = ICONS[3]
|
||||
_attr_native_min_value: float = 0
|
||||
_attr_native_max_value: float = 127
|
||||
_zcl_attribute: str = "ramp_rate_on_to_off_remote"
|
||||
_attribute_name = "ramp_rate_on_to_off_remote"
|
||||
_attr_translation_key: str = "ramp_rate_on_to_off_remote"
|
||||
|
||||
|
||||
@ -748,7 +746,7 @@ class InovelliMinimumLoadDimmingLevel(ZHANumberConfigurationEntity):
|
||||
_attr_icon: str = ICONS[16]
|
||||
_attr_native_min_value: float = 1
|
||||
_attr_native_max_value: float = 254
|
||||
_zcl_attribute: str = "minimum_level"
|
||||
_attribute_name = "minimum_level"
|
||||
_attr_translation_key: str = "minimum_level"
|
||||
|
||||
|
||||
@ -762,7 +760,7 @@ class InovelliMaximumLoadDimmingLevel(ZHANumberConfigurationEntity):
|
||||
_attr_icon: str = ICONS[16]
|
||||
_attr_native_min_value: float = 2
|
||||
_attr_native_max_value: float = 255
|
||||
_zcl_attribute: str = "maximum_level"
|
||||
_attribute_name = "maximum_level"
|
||||
_attr_translation_key: str = "maximum_level"
|
||||
|
||||
|
||||
@ -776,7 +774,7 @@ class InovelliAutoShutoffTimer(ZHANumberConfigurationEntity):
|
||||
_attr_icon: str = ICONS[14]
|
||||
_attr_native_min_value: float = 0
|
||||
_attr_native_max_value: float = 32767
|
||||
_zcl_attribute: str = "auto_off_timer"
|
||||
_attribute_name = "auto_off_timer"
|
||||
_attr_translation_key: str = "auto_off_timer"
|
||||
|
||||
|
||||
@ -790,7 +788,7 @@ class InovelliLoadLevelIndicatorTimeout(ZHANumberConfigurationEntity):
|
||||
_attr_icon: str = ICONS[14]
|
||||
_attr_native_min_value: float = 0
|
||||
_attr_native_max_value: float = 11
|
||||
_zcl_attribute: str = "load_level_indicator_timeout"
|
||||
_attribute_name = "load_level_indicator_timeout"
|
||||
_attr_translation_key: str = "load_level_indicator_timeout"
|
||||
|
||||
|
||||
@ -804,7 +802,7 @@ class InovelliDefaultAllLEDOnColor(ZHANumberConfigurationEntity):
|
||||
_attr_icon: str = ICONS[15]
|
||||
_attr_native_min_value: float = 0
|
||||
_attr_native_max_value: float = 255
|
||||
_zcl_attribute: str = "led_color_when_on"
|
||||
_attribute_name = "led_color_when_on"
|
||||
_attr_translation_key: str = "led_color_when_on"
|
||||
|
||||
|
||||
@ -818,7 +816,7 @@ class InovelliDefaultAllLEDOffColor(ZHANumberConfigurationEntity):
|
||||
_attr_icon: str = ICONS[15]
|
||||
_attr_native_min_value: float = 0
|
||||
_attr_native_max_value: float = 255
|
||||
_zcl_attribute: str = "led_color_when_off"
|
||||
_attribute_name = "led_color_when_off"
|
||||
_attr_translation_key: str = "led_color_when_off"
|
||||
|
||||
|
||||
@ -832,7 +830,7 @@ class InovelliDefaultAllLEDOnIntensity(ZHANumberConfigurationEntity):
|
||||
_attr_icon: str = ICONS[16]
|
||||
_attr_native_min_value: float = 0
|
||||
_attr_native_max_value: float = 100
|
||||
_zcl_attribute: str = "led_intensity_when_on"
|
||||
_attribute_name = "led_intensity_when_on"
|
||||
_attr_translation_key: str = "led_intensity_when_on"
|
||||
|
||||
|
||||
@ -846,7 +844,7 @@ class InovelliDefaultAllLEDOffIntensity(ZHANumberConfigurationEntity):
|
||||
_attr_icon: str = ICONS[16]
|
||||
_attr_native_min_value: float = 0
|
||||
_attr_native_max_value: float = 100
|
||||
_zcl_attribute: str = "led_intensity_when_off"
|
||||
_attribute_name = "led_intensity_when_off"
|
||||
_attr_translation_key: str = "led_intensity_when_off"
|
||||
|
||||
|
||||
@ -860,7 +858,7 @@ class InovelliDoubleTapUpLevel(ZHANumberConfigurationEntity):
|
||||
_attr_icon: str = ICONS[16]
|
||||
_attr_native_min_value: float = 2
|
||||
_attr_native_max_value: float = 254
|
||||
_zcl_attribute: str = "double_tap_up_level"
|
||||
_attribute_name = "double_tap_up_level"
|
||||
_attr_translation_key: str = "double_tap_up_level"
|
||||
|
||||
|
||||
@ -874,7 +872,7 @@ class InovelliDoubleTapDownLevel(ZHANumberConfigurationEntity):
|
||||
_attr_icon: str = ICONS[16]
|
||||
_attr_native_min_value: float = 0
|
||||
_attr_native_max_value: float = 254
|
||||
_zcl_attribute: str = "double_tap_down_level"
|
||||
_attribute_name = "double_tap_down_level"
|
||||
_attr_translation_key: str = "double_tap_down_level"
|
||||
|
||||
|
||||
@ -889,7 +887,7 @@ class AqaraPetFeederServingSize(ZHANumberConfigurationEntity):
|
||||
_attr_entity_category = EntityCategory.CONFIG
|
||||
_attr_native_min_value: float = 1
|
||||
_attr_native_max_value: float = 10
|
||||
_zcl_attribute: str = "serving_size"
|
||||
_attribute_name = "serving_size"
|
||||
_attr_translation_key: str = "serving_size"
|
||||
|
||||
_attr_mode: NumberMode = NumberMode.BOX
|
||||
@ -907,7 +905,7 @@ class AqaraPetFeederPortionWeight(ZHANumberConfigurationEntity):
|
||||
_attr_entity_category = EntityCategory.CONFIG
|
||||
_attr_native_min_value: float = 1
|
||||
_attr_native_max_value: float = 100
|
||||
_zcl_attribute: str = "portion_weight"
|
||||
_attribute_name = "portion_weight"
|
||||
_attr_translation_key: str = "portion_weight"
|
||||
|
||||
_attr_mode: NumberMode = NumberMode.BOX
|
||||
@ -927,7 +925,7 @@ class AqaraThermostatAwayTemp(ZHANumberConfigurationEntity):
|
||||
_attr_native_min_value: float = 5
|
||||
_attr_native_max_value: float = 30
|
||||
_attr_multiplier: float = 0.01
|
||||
_zcl_attribute: str = "away_preset_temperature"
|
||||
_attribute_name = "away_preset_temperature"
|
||||
_attr_translation_key: str = "away_preset_temperature"
|
||||
|
||||
_attr_mode: NumberMode = NumberMode.SLIDER
|
||||
|
@ -67,7 +67,7 @@ class ZHAEnumSelectEntity(ZhaEntity, SelectEntity):
|
||||
"""Representation of a ZHA select entity."""
|
||||
|
||||
_attr_entity_category = EntityCategory.CONFIG
|
||||
_attribute: str
|
||||
_attribute_name: str
|
||||
_enum: type[Enum]
|
||||
|
||||
def __init__(
|
||||
@ -78,7 +78,7 @@ class ZHAEnumSelectEntity(ZhaEntity, SelectEntity):
|
||||
**kwargs: Any,
|
||||
) -> None:
|
||||
"""Init this select entity."""
|
||||
self._attribute = self._enum.__name__
|
||||
self._attribute_name = self._enum.__name__
|
||||
self._attr_options = [entry.name.replace("_", " ") for entry in self._enum]
|
||||
self._cluster_handler: ClusterHandler = cluster_handlers[0]
|
||||
super().__init__(unique_id, zha_device, cluster_handlers, **kwargs)
|
||||
@ -86,14 +86,14 @@ class ZHAEnumSelectEntity(ZhaEntity, SelectEntity):
|
||||
@property
|
||||
def current_option(self) -> str | None:
|
||||
"""Return the selected entity option to represent the entity state."""
|
||||
option = self._cluster_handler.data_cache.get(self._attribute)
|
||||
option = self._cluster_handler.data_cache.get(self._attribute_name)
|
||||
if option is None:
|
||||
return None
|
||||
return option.name.replace("_", " ")
|
||||
|
||||
async def async_select_option(self, option: str) -> None:
|
||||
"""Change the selected option."""
|
||||
self._cluster_handler.data_cache[self._attribute] = self._enum[
|
||||
self._cluster_handler.data_cache[self._attribute_name] = self._enum[
|
||||
option.replace(" ", "_")
|
||||
]
|
||||
self.async_write_ha_state()
|
||||
@ -102,7 +102,7 @@ class ZHAEnumSelectEntity(ZhaEntity, SelectEntity):
|
||||
def async_restore_last_state(self, last_state) -> None:
|
||||
"""Restore previous state."""
|
||||
if last_state.state and last_state.state != STATE_UNKNOWN:
|
||||
self._cluster_handler.data_cache[self._attribute] = self._enum[
|
||||
self._cluster_handler.data_cache[self._attribute_name] = self._enum[
|
||||
last_state.state.replace(" ", "_")
|
||||
]
|
||||
|
||||
|
@ -118,7 +118,7 @@ async def async_setup_entry(
|
||||
class Sensor(ZhaEntity, SensorEntity):
|
||||
"""Base ZHA sensor."""
|
||||
|
||||
SENSOR_ATTR: int | str | None = None
|
||||
_attribute_name: int | str | None = None
|
||||
_decimals: int = 1
|
||||
_divisor: int = 1
|
||||
_multiplier: int | float = 1
|
||||
@ -148,8 +148,8 @@ class Sensor(ZhaEntity, SensorEntity):
|
||||
"""
|
||||
cluster_handler = cluster_handlers[0]
|
||||
if (
|
||||
cls.SENSOR_ATTR in cluster_handler.cluster.unsupported_attributes
|
||||
or cls.SENSOR_ATTR not in cluster_handler.cluster.attributes_by_name
|
||||
cls._attribute_name in cluster_handler.cluster.unsupported_attributes
|
||||
or cls._attribute_name not in cluster_handler.cluster.attributes_by_name
|
||||
):
|
||||
return None
|
||||
|
||||
@ -165,8 +165,8 @@ class Sensor(ZhaEntity, SensorEntity):
|
||||
@property
|
||||
def native_value(self) -> StateType:
|
||||
"""Return the state of the entity."""
|
||||
assert self.SENSOR_ATTR is not None
|
||||
raw_state = self._cluster_handler.cluster.get(self.SENSOR_ATTR)
|
||||
assert self._attribute_name is not None
|
||||
raw_state = self._cluster_handler.cluster.get(self._attribute_name)
|
||||
if raw_state is None:
|
||||
return None
|
||||
return self.formatter(raw_state)
|
||||
@ -194,7 +194,7 @@ class Sensor(ZhaEntity, SensorEntity):
|
||||
class AnalogInput(Sensor):
|
||||
"""Sensor that displays analog input values."""
|
||||
|
||||
SENSOR_ATTR = "present_value"
|
||||
_attribute_name = "present_value"
|
||||
_attr_translation_key: str = "analog_input"
|
||||
|
||||
|
||||
@ -203,7 +203,7 @@ class AnalogInput(Sensor):
|
||||
class Battery(Sensor):
|
||||
"""Battery sensor of power configuration cluster."""
|
||||
|
||||
SENSOR_ATTR = "battery_percentage_remaining"
|
||||
_attribute_name = "battery_percentage_remaining"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.BATTERY
|
||||
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
|
||||
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||
@ -261,7 +261,7 @@ class Battery(Sensor):
|
||||
class ElectricalMeasurement(Sensor):
|
||||
"""Active power measurement."""
|
||||
|
||||
SENSOR_ATTR = "active_power"
|
||||
_attribute_name = "active_power"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.POWER
|
||||
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
|
||||
_attr_native_unit_of_measurement: str = UnitOfPower.WATT
|
||||
@ -274,7 +274,7 @@ class ElectricalMeasurement(Sensor):
|
||||
if self._cluster_handler.measurement_type is not None:
|
||||
attrs["measurement_type"] = self._cluster_handler.measurement_type
|
||||
|
||||
max_attr_name = f"{self.SENSOR_ATTR}_max"
|
||||
max_attr_name = f"{self._attribute_name}_max"
|
||||
|
||||
try:
|
||||
max_v = self._cluster_handler.cluster.get(max_attr_name)
|
||||
@ -320,7 +320,7 @@ class PolledElectricalMeasurement(ElectricalMeasurement):
|
||||
class ElectricalMeasurementApparentPower(ElectricalMeasurement):
|
||||
"""Apparent power measurement."""
|
||||
|
||||
SENSOR_ATTR = "apparent_power"
|
||||
_attribute_name = "apparent_power"
|
||||
_unique_id_suffix = "apparent_power"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.APPARENT_POWER
|
||||
_attr_native_unit_of_measurement = UnitOfApparentPower.VOLT_AMPERE
|
||||
@ -332,7 +332,7 @@ class ElectricalMeasurementApparentPower(ElectricalMeasurement):
|
||||
class ElectricalMeasurementRMSCurrent(ElectricalMeasurement):
|
||||
"""RMS current measurement."""
|
||||
|
||||
SENSOR_ATTR = "rms_current"
|
||||
_attribute_name = "rms_current"
|
||||
_unique_id_suffix = "rms_current"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.CURRENT
|
||||
_attr_native_unit_of_measurement = UnitOfElectricCurrent.AMPERE
|
||||
@ -344,7 +344,7 @@ class ElectricalMeasurementRMSCurrent(ElectricalMeasurement):
|
||||
class ElectricalMeasurementRMSVoltage(ElectricalMeasurement):
|
||||
"""RMS Voltage measurement."""
|
||||
|
||||
SENSOR_ATTR = "rms_voltage"
|
||||
_attribute_name = "rms_voltage"
|
||||
_unique_id_suffix = "rms_voltage"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.VOLTAGE
|
||||
_attr_native_unit_of_measurement = UnitOfElectricPotential.VOLT
|
||||
@ -356,7 +356,7 @@ class ElectricalMeasurementRMSVoltage(ElectricalMeasurement):
|
||||
class ElectricalMeasurementFrequency(ElectricalMeasurement):
|
||||
"""Frequency measurement."""
|
||||
|
||||
SENSOR_ATTR = "ac_frequency"
|
||||
_attribute_name = "ac_frequency"
|
||||
_unique_id_suffix = "ac_frequency"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.FREQUENCY
|
||||
_attr_translation_key: str = "ac_frequency"
|
||||
@ -369,7 +369,7 @@ class ElectricalMeasurementFrequency(ElectricalMeasurement):
|
||||
class ElectricalMeasurementPowerFactor(ElectricalMeasurement):
|
||||
"""Frequency measurement."""
|
||||
|
||||
SENSOR_ATTR = "power_factor"
|
||||
_attribute_name = "power_factor"
|
||||
_unique_id_suffix = "power_factor"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.POWER_FACTOR
|
||||
_attr_native_unit_of_measurement = PERCENTAGE
|
||||
@ -387,7 +387,7 @@ class ElectricalMeasurementPowerFactor(ElectricalMeasurement):
|
||||
class Humidity(Sensor):
|
||||
"""Humidity sensor."""
|
||||
|
||||
SENSOR_ATTR = "measured_value"
|
||||
_attribute_name = "measured_value"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.HUMIDITY
|
||||
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
|
||||
_divisor = 100
|
||||
@ -399,7 +399,7 @@ class Humidity(Sensor):
|
||||
class SoilMoisture(Sensor):
|
||||
"""Soil Moisture sensor."""
|
||||
|
||||
SENSOR_ATTR = "measured_value"
|
||||
_attribute_name = "measured_value"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.HUMIDITY
|
||||
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
|
||||
_attr_translation_key: str = "soil_moisture"
|
||||
@ -412,7 +412,7 @@ class SoilMoisture(Sensor):
|
||||
class LeafWetness(Sensor):
|
||||
"""Leaf Wetness sensor."""
|
||||
|
||||
SENSOR_ATTR = "measured_value"
|
||||
_attribute_name = "measured_value"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.HUMIDITY
|
||||
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
|
||||
_attr_translation_key: str = "leaf_wetness"
|
||||
@ -425,7 +425,7 @@ class LeafWetness(Sensor):
|
||||
class Illuminance(Sensor):
|
||||
"""Illuminance Sensor."""
|
||||
|
||||
SENSOR_ATTR = "measured_value"
|
||||
_attribute_name = "measured_value"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.ILLUMINANCE
|
||||
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
|
||||
_attr_native_unit_of_measurement = LIGHT_LUX
|
||||
@ -443,7 +443,7 @@ class Illuminance(Sensor):
|
||||
class SmartEnergyMetering(Sensor):
|
||||
"""Metering sensor."""
|
||||
|
||||
SENSOR_ATTR: int | str = "instantaneous_demand"
|
||||
_attribute_name = "instantaneous_demand"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.POWER
|
||||
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
|
||||
_attr_translation_key: str = "instantaneous_demand"
|
||||
@ -497,7 +497,7 @@ class SmartEnergyMetering(Sensor):
|
||||
class SmartEnergySummation(SmartEnergyMetering):
|
||||
"""Smart Energy Metering summation sensor."""
|
||||
|
||||
SENSOR_ATTR: int | str = "current_summ_delivered"
|
||||
_attribute_name = "current_summ_delivered"
|
||||
_unique_id_suffix = "summation_delivered"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.ENERGY
|
||||
_attr_state_class: SensorStateClass = SensorStateClass.TOTAL_INCREASING
|
||||
@ -557,7 +557,7 @@ class PolledSmartEnergySummation(SmartEnergySummation):
|
||||
class Tier1SmartEnergySummation(PolledSmartEnergySummation):
|
||||
"""Tier 1 Smart Energy Metering summation sensor."""
|
||||
|
||||
SENSOR_ATTR: int | str = "current_tier1_summ_delivered"
|
||||
_attribute_name = "current_tier1_summ_delivered"
|
||||
_unique_id_suffix = "tier1_summation_delivered"
|
||||
_attr_translation_key: str = "tier1_summation_delivered"
|
||||
|
||||
@ -570,7 +570,7 @@ class Tier1SmartEnergySummation(PolledSmartEnergySummation):
|
||||
class Tier2SmartEnergySummation(PolledSmartEnergySummation):
|
||||
"""Tier 2 Smart Energy Metering summation sensor."""
|
||||
|
||||
SENSOR_ATTR: int | str = "current_tier2_summ_delivered"
|
||||
_attribute_name = "current_tier2_summ_delivered"
|
||||
_unique_id_suffix = "tier2_summation_delivered"
|
||||
_attr_translation_key: str = "tier2_summation_delivered"
|
||||
|
||||
@ -583,7 +583,7 @@ class Tier2SmartEnergySummation(PolledSmartEnergySummation):
|
||||
class Tier3SmartEnergySummation(PolledSmartEnergySummation):
|
||||
"""Tier 3 Smart Energy Metering summation sensor."""
|
||||
|
||||
SENSOR_ATTR: int | str = "current_tier3_summ_delivered"
|
||||
_attribute_name = "current_tier3_summ_delivered"
|
||||
_unique_id_suffix = "tier3_summation_delivered"
|
||||
_attr_translation_key: str = "tier3_summation_delivered"
|
||||
|
||||
@ -596,7 +596,7 @@ class Tier3SmartEnergySummation(PolledSmartEnergySummation):
|
||||
class Tier4SmartEnergySummation(PolledSmartEnergySummation):
|
||||
"""Tier 4 Smart Energy Metering summation sensor."""
|
||||
|
||||
SENSOR_ATTR: int | str = "current_tier4_summ_delivered"
|
||||
_attribute_name = "current_tier4_summ_delivered"
|
||||
_unique_id_suffix = "tier4_summation_delivered"
|
||||
_attr_translation_key: str = "tier4_summation_delivered"
|
||||
|
||||
@ -609,7 +609,7 @@ class Tier4SmartEnergySummation(PolledSmartEnergySummation):
|
||||
class Tier5SmartEnergySummation(PolledSmartEnergySummation):
|
||||
"""Tier 5 Smart Energy Metering summation sensor."""
|
||||
|
||||
SENSOR_ATTR: int | str = "current_tier5_summ_delivered"
|
||||
_attribute_name = "current_tier5_summ_delivered"
|
||||
_unique_id_suffix = "tier5_summation_delivered"
|
||||
_attr_translation_key: str = "tier5_summation_delivered"
|
||||
|
||||
@ -622,7 +622,7 @@ class Tier5SmartEnergySummation(PolledSmartEnergySummation):
|
||||
class Tier6SmartEnergySummation(PolledSmartEnergySummation):
|
||||
"""Tier 6 Smart Energy Metering summation sensor."""
|
||||
|
||||
SENSOR_ATTR: int | str = "current_tier6_summ_delivered"
|
||||
_attribute_name = "current_tier6_summ_delivered"
|
||||
_unique_id_suffix = "tier6_summation_delivered"
|
||||
_attr_translation_key: str = "tier6_summation_delivered"
|
||||
|
||||
@ -632,7 +632,7 @@ class Tier6SmartEnergySummation(PolledSmartEnergySummation):
|
||||
class Pressure(Sensor):
|
||||
"""Pressure sensor."""
|
||||
|
||||
SENSOR_ATTR = "measured_value"
|
||||
_attribute_name = "measured_value"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.PRESSURE
|
||||
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
|
||||
_decimals = 0
|
||||
@ -644,7 +644,7 @@ class Pressure(Sensor):
|
||||
class Temperature(Sensor):
|
||||
"""Temperature Sensor."""
|
||||
|
||||
SENSOR_ATTR = "measured_value"
|
||||
_attribute_name = "measured_value"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.TEMPERATURE
|
||||
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
|
||||
_divisor = 100
|
||||
@ -656,7 +656,7 @@ class Temperature(Sensor):
|
||||
class DeviceTemperature(Sensor):
|
||||
"""Device Temperature Sensor."""
|
||||
|
||||
SENSOR_ATTR = "current_temperature"
|
||||
_attribute_name = "current_temperature"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.TEMPERATURE
|
||||
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
|
||||
_attr_translation_key: str = "device_temperature"
|
||||
@ -670,7 +670,7 @@ class DeviceTemperature(Sensor):
|
||||
class CarbonDioxideConcentration(Sensor):
|
||||
"""Carbon Dioxide Concentration sensor."""
|
||||
|
||||
SENSOR_ATTR = "measured_value"
|
||||
_attribute_name = "measured_value"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.CO2
|
||||
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
|
||||
_decimals = 0
|
||||
@ -683,7 +683,7 @@ class CarbonDioxideConcentration(Sensor):
|
||||
class CarbonMonoxideConcentration(Sensor):
|
||||
"""Carbon Monoxide Concentration sensor."""
|
||||
|
||||
SENSOR_ATTR = "measured_value"
|
||||
_attribute_name = "measured_value"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.CO
|
||||
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
|
||||
_decimals = 0
|
||||
@ -697,7 +697,7 @@ class CarbonMonoxideConcentration(Sensor):
|
||||
class VOCLevel(Sensor):
|
||||
"""VOC Level sensor."""
|
||||
|
||||
SENSOR_ATTR = "measured_value"
|
||||
_attribute_name = "measured_value"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS
|
||||
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
|
||||
_decimals = 0
|
||||
@ -714,7 +714,7 @@ class VOCLevel(Sensor):
|
||||
class PPBVOCLevel(Sensor):
|
||||
"""VOC Level sensor."""
|
||||
|
||||
SENSOR_ATTR = "measured_value"
|
||||
_attribute_name = "measured_value"
|
||||
_attr_device_class: SensorDeviceClass = (
|
||||
SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS_PARTS
|
||||
)
|
||||
@ -729,7 +729,7 @@ class PPBVOCLevel(Sensor):
|
||||
class PM25(Sensor):
|
||||
"""Particulate Matter 2.5 microns or less sensor."""
|
||||
|
||||
SENSOR_ATTR = "measured_value"
|
||||
_attribute_name = "measured_value"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.PM25
|
||||
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
|
||||
_decimals = 0
|
||||
@ -742,7 +742,7 @@ class PM25(Sensor):
|
||||
class FormaldehydeConcentration(Sensor):
|
||||
"""Formaldehyde Concentration sensor."""
|
||||
|
||||
SENSOR_ATTR = "measured_value"
|
||||
_attribute_name = "measured_value"
|
||||
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
|
||||
_attr_translation_key: str = "formaldehyde"
|
||||
_decimals = 0
|
||||
@ -878,7 +878,7 @@ class SinopeHVACAction(ThermostatHVACAction):
|
||||
class RSSISensor(Sensor):
|
||||
"""RSSI sensor for a device."""
|
||||
|
||||
SENSOR_ATTR = "rssi"
|
||||
_attribute_name = "rssi"
|
||||
_unique_id_suffix = "rssi"
|
||||
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
|
||||
_attr_device_class: SensorDeviceClass | None = SensorDeviceClass.SIGNAL_STRENGTH
|
||||
@ -908,7 +908,7 @@ class RSSISensor(Sensor):
|
||||
@property
|
||||
def native_value(self) -> StateType:
|
||||
"""Return the state of the entity."""
|
||||
return getattr(self._zha_device.device, self.SENSOR_ATTR)
|
||||
return getattr(self._zha_device.device, self._attribute_name)
|
||||
|
||||
|
||||
@MULTI_MATCH(cluster_handler_names=CLUSTER_HANDLER_BASIC)
|
||||
@ -916,7 +916,7 @@ class RSSISensor(Sensor):
|
||||
class LQISensor(RSSISensor):
|
||||
"""LQI sensor for a device."""
|
||||
|
||||
SENSOR_ATTR = "lqi"
|
||||
_attribute_name = "lqi"
|
||||
_unique_id_suffix = "lqi"
|
||||
_attr_device_class = None
|
||||
_attr_native_unit_of_measurement = None
|
||||
@ -933,7 +933,7 @@ class LQISensor(RSSISensor):
|
||||
class TimeLeft(Sensor):
|
||||
"""Sensor that displays time left value."""
|
||||
|
||||
SENSOR_ATTR = "timer_time_left"
|
||||
_attribute_name = "timer_time_left"
|
||||
_unique_id_suffix = "time_left"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.DURATION
|
||||
_attr_icon = "mdi:timer"
|
||||
@ -946,7 +946,7 @@ class TimeLeft(Sensor):
|
||||
class IkeaDeviceRunTime(Sensor):
|
||||
"""Sensor that displays device run time (in minutes)."""
|
||||
|
||||
SENSOR_ATTR = "device_run_time"
|
||||
_attribute_name = "device_run_time"
|
||||
_unique_id_suffix = "device_run_time"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.DURATION
|
||||
_attr_icon = "mdi:timer"
|
||||
@ -960,7 +960,7 @@ class IkeaDeviceRunTime(Sensor):
|
||||
class IkeaFilterRunTime(Sensor):
|
||||
"""Sensor that displays run time of the current filter (in minutes)."""
|
||||
|
||||
SENSOR_ATTR = "filter_run_time"
|
||||
_attribute_name = "filter_run_time"
|
||||
_unique_id_suffix = "filter_run_time"
|
||||
_attr_device_class: SensorDeviceClass = SensorDeviceClass.DURATION
|
||||
_attr_icon = "mdi:timer"
|
||||
@ -981,7 +981,7 @@ class AqaraFeedingSource(types.enum8):
|
||||
class AqaraPetFeederLastFeedingSource(Sensor):
|
||||
"""Sensor that displays the last feeding source of pet feeder."""
|
||||
|
||||
SENSOR_ATTR = "last_feeding_source"
|
||||
_attribute_name = "last_feeding_source"
|
||||
_unique_id_suffix = "last_feeding_source"
|
||||
_attr_translation_key: str = "last_feeding_source"
|
||||
_attr_icon = "mdi:devices"
|
||||
@ -996,7 +996,7 @@ class AqaraPetFeederLastFeedingSource(Sensor):
|
||||
class AqaraPetFeederLastFeedingSize(Sensor):
|
||||
"""Sensor that displays the last feeding size of the pet feeder."""
|
||||
|
||||
SENSOR_ATTR = "last_feeding_size"
|
||||
_attribute_name = "last_feeding_size"
|
||||
_unique_id_suffix = "last_feeding_size"
|
||||
_attr_translation_key: str = "last_feeding_size"
|
||||
_attr_icon: str = "mdi:counter"
|
||||
@ -1007,7 +1007,7 @@ class AqaraPetFeederLastFeedingSize(Sensor):
|
||||
class AqaraPetFeederPortionsDispensed(Sensor):
|
||||
"""Sensor that displays the number of portions dispensed by the pet feeder."""
|
||||
|
||||
SENSOR_ATTR = "portions_dispensed"
|
||||
_attribute_name = "portions_dispensed"
|
||||
_unique_id_suffix = "portions_dispensed"
|
||||
_attr_translation_key: str = "portions_dispensed_today"
|
||||
_attr_state_class: SensorStateClass = SensorStateClass.TOTAL_INCREASING
|
||||
@ -1019,7 +1019,7 @@ class AqaraPetFeederPortionsDispensed(Sensor):
|
||||
class AqaraPetFeederWeightDispensed(Sensor):
|
||||
"""Sensor that displays the weight dispensed by the pet feeder."""
|
||||
|
||||
SENSOR_ATTR = "weight_dispensed"
|
||||
_attribute_name = "weight_dispensed"
|
||||
_unique_id_suffix = "weight_dispensed"
|
||||
_attr_translation_key: str = "weight_dispensed_today"
|
||||
_attr_native_unit_of_measurement = UnitOfMass.GRAMS
|
||||
@ -1032,7 +1032,7 @@ class AqaraPetFeederWeightDispensed(Sensor):
|
||||
class AqaraSmokeDensityDbm(Sensor):
|
||||
"""Sensor that displays the smoke density of an Aqara smoke sensor in dB/m."""
|
||||
|
||||
SENSOR_ATTR = "smoke_density_dbm"
|
||||
_attribute_name = "smoke_density_dbm"
|
||||
_unique_id_suffix = "smoke_density_dbm"
|
||||
_attr_translation_key: str = "smoke_density"
|
||||
_attr_native_unit_of_measurement = "dB/m"
|
||||
|
@ -168,8 +168,8 @@ class ZHASwitchConfigurationEntity(ZhaEntity, SwitchEntity):
|
||||
"""Representation of a ZHA switch configuration entity."""
|
||||
|
||||
_attr_entity_category = EntityCategory.CONFIG
|
||||
_zcl_attribute: str
|
||||
_zcl_inverter_attribute: str | None = None
|
||||
_attribute_name: str
|
||||
_inverter_attribute_name: str | None = None
|
||||
_force_inverted: bool = False
|
||||
|
||||
@classmethod
|
||||
@ -186,13 +186,13 @@ class ZHASwitchConfigurationEntity(ZhaEntity, SwitchEntity):
|
||||
"""
|
||||
cluster_handler = cluster_handlers[0]
|
||||
if (
|
||||
cls._zcl_attribute in cluster_handler.cluster.unsupported_attributes
|
||||
or cls._zcl_attribute not in cluster_handler.cluster.attributes_by_name
|
||||
or cluster_handler.cluster.get(cls._zcl_attribute) is None
|
||||
cls._attribute_name in cluster_handler.cluster.unsupported_attributes
|
||||
or cls._attribute_name not in cluster_handler.cluster.attributes_by_name
|
||||
or cluster_handler.cluster.get(cls._attribute_name) is None
|
||||
):
|
||||
_LOGGER.debug(
|
||||
"%s is not supported - skipping %s entity creation",
|
||||
cls._zcl_attribute,
|
||||
cls._attribute_name,
|
||||
cls.__name__,
|
||||
)
|
||||
return None
|
||||
@ -225,20 +225,22 @@ class ZHASwitchConfigurationEntity(ZhaEntity, SwitchEntity):
|
||||
@property
|
||||
def inverted(self) -> bool:
|
||||
"""Return True if the switch is inverted."""
|
||||
if self._zcl_inverter_attribute:
|
||||
return bool(self._cluster_handler.cluster.get(self._zcl_inverter_attribute))
|
||||
if self._inverter_attribute_name:
|
||||
return bool(
|
||||
self._cluster_handler.cluster.get(self._inverter_attribute_name)
|
||||
)
|
||||
return self._force_inverted
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return if the switch is on based on the statemachine."""
|
||||
val = bool(self._cluster_handler.cluster.get(self._zcl_attribute))
|
||||
val = bool(self._cluster_handler.cluster.get(self._attribute_name))
|
||||
return (not val) if self.inverted else val
|
||||
|
||||
async def async_turn_on_off(self, state: bool) -> None:
|
||||
"""Turn the entity on or off."""
|
||||
await self._cluster_handler.write_attributes_safe(
|
||||
{self._zcl_attribute: not state if self.inverted else state}
|
||||
{self._attribute_name: not state if self.inverted else state}
|
||||
)
|
||||
self.async_write_ha_state()
|
||||
|
||||
@ -256,10 +258,10 @@ class ZHASwitchConfigurationEntity(ZhaEntity, SwitchEntity):
|
||||
self.error("Polling current state")
|
||||
if self._cluster_handler:
|
||||
value = await self._cluster_handler.get_attribute_value(
|
||||
self._zcl_attribute, from_cache=False
|
||||
self._attribute_name, from_cache=False
|
||||
)
|
||||
await self._cluster_handler.get_attribute_value(
|
||||
self._zcl_inverter_attribute, from_cache=False
|
||||
self._inverter_attribute_name, from_cache=False
|
||||
)
|
||||
self.debug("read value=%s, inverted=%s", value, self.inverted)
|
||||
|
||||
@ -274,8 +276,8 @@ class OnOffWindowDetectionFunctionConfigurationEntity(ZHASwitchConfigurationEnti
|
||||
"""Representation of a ZHA window detection configuration entity."""
|
||||
|
||||
_unique_id_suffix = "on_off_window_opened_detection"
|
||||
_zcl_attribute: str = "window_detection_function"
|
||||
_zcl_inverter_attribute: str = "window_detection_function_inverter"
|
||||
_attribute_name = "window_detection_function"
|
||||
_inverter_attribute_name = "window_detection_function_inverter"
|
||||
_attr_translation_key = "window_detection_function"
|
||||
|
||||
|
||||
@ -286,7 +288,7 @@ class P1MotionTriggerIndicatorSwitch(ZHASwitchConfigurationEntity):
|
||||
"""Representation of a ZHA motion triggering configuration entity."""
|
||||
|
||||
_unique_id_suffix = "trigger_indicator"
|
||||
_zcl_attribute: str = "trigger_indicator"
|
||||
_attribute_name = "trigger_indicator"
|
||||
_attr_translation_key = "trigger_indicator"
|
||||
|
||||
|
||||
@ -298,7 +300,7 @@ class XiaomiPlugPowerOutageMemorySwitch(ZHASwitchConfigurationEntity):
|
||||
"""Representation of a ZHA power outage memory configuration entity."""
|
||||
|
||||
_unique_id_suffix = "power_outage_memory"
|
||||
_zcl_attribute: str = "power_outage_memory"
|
||||
_attribute_name = "power_outage_memory"
|
||||
_attr_translation_key = "power_outage_memory"
|
||||
|
||||
|
||||
@ -311,7 +313,7 @@ class HueMotionTriggerIndicatorSwitch(ZHASwitchConfigurationEntity):
|
||||
"""Representation of a ZHA motion triggering configuration entity."""
|
||||
|
||||
_unique_id_suffix = "trigger_indicator"
|
||||
_zcl_attribute: str = "trigger_indicator"
|
||||
_attribute_name = "trigger_indicator"
|
||||
_attr_translation_key = "trigger_indicator"
|
||||
|
||||
|
||||
@ -323,7 +325,7 @@ class ChildLock(ZHASwitchConfigurationEntity):
|
||||
"""ZHA BinarySensor."""
|
||||
|
||||
_unique_id_suffix = "child_lock"
|
||||
_zcl_attribute: str = "child_lock"
|
||||
_attribute_name = "child_lock"
|
||||
_attr_translation_key = "child_lock"
|
||||
|
||||
|
||||
@ -335,7 +337,7 @@ class DisableLed(ZHASwitchConfigurationEntity):
|
||||
"""ZHA BinarySensor."""
|
||||
|
||||
_unique_id_suffix = "disable_led"
|
||||
_zcl_attribute: str = "disable_led"
|
||||
_attribute_name = "disable_led"
|
||||
_attr_translation_key = "disable_led"
|
||||
|
||||
|
||||
@ -346,7 +348,7 @@ class InovelliInvertSwitch(ZHASwitchConfigurationEntity):
|
||||
"""Inovelli invert switch control."""
|
||||
|
||||
_unique_id_suffix = "invert_switch"
|
||||
_zcl_attribute: str = "invert_switch"
|
||||
_attribute_name = "invert_switch"
|
||||
_attr_translation_key = "invert_switch"
|
||||
|
||||
|
||||
@ -357,7 +359,7 @@ class InovelliSmartBulbMode(ZHASwitchConfigurationEntity):
|
||||
"""Inovelli smart bulb mode control."""
|
||||
|
||||
_unique_id_suffix = "smart_bulb_mode"
|
||||
_zcl_attribute: str = "smart_bulb_mode"
|
||||
_attribute_name = "smart_bulb_mode"
|
||||
_attr_translation_key = "smart_bulb_mode"
|
||||
|
||||
|
||||
@ -368,7 +370,7 @@ class InovelliDoubleTapUpEnabled(ZHASwitchConfigurationEntity):
|
||||
"""Inovelli double tap up enabled."""
|
||||
|
||||
_unique_id_suffix = "double_tap_up_enabled"
|
||||
_zcl_attribute: str = "double_tap_up_enabled"
|
||||
_attribute_name = "double_tap_up_enabled"
|
||||
_attr_translation_key = "double_tap_up_enabled"
|
||||
|
||||
|
||||
@ -379,7 +381,7 @@ class InovelliDoubleTapDownEnabled(ZHASwitchConfigurationEntity):
|
||||
"""Inovelli double tap down enabled."""
|
||||
|
||||
_unique_id_suffix = "double_tap_down_enabled"
|
||||
_zcl_attribute: str = "double_tap_down_enabled"
|
||||
_attribute_name = "double_tap_down_enabled"
|
||||
_attr_translation_key = "double_tap_down_enabled"
|
||||
|
||||
|
||||
@ -390,7 +392,7 @@ class InovelliAuxSwitchScenes(ZHASwitchConfigurationEntity):
|
||||
"""Inovelli unique aux switch scenes."""
|
||||
|
||||
_unique_id_suffix = "aux_switch_scenes"
|
||||
_zcl_attribute: str = "aux_switch_scenes"
|
||||
_attribute_name = "aux_switch_scenes"
|
||||
_attr_translation_key = "aux_switch_scenes"
|
||||
|
||||
|
||||
@ -401,7 +403,7 @@ class InovelliBindingOffToOnSyncLevel(ZHASwitchConfigurationEntity):
|
||||
"""Inovelli send move to level with on/off to bound devices."""
|
||||
|
||||
_unique_id_suffix = "binding_off_to_on_sync_level"
|
||||
_zcl_attribute: str = "binding_off_to_on_sync_level"
|
||||
_attribute_name = "binding_off_to_on_sync_level"
|
||||
_attr_translation_key = "binding_off_to_on_sync_level"
|
||||
|
||||
|
||||
@ -412,7 +414,7 @@ class InovelliLocalProtection(ZHASwitchConfigurationEntity):
|
||||
"""Inovelli local protection control."""
|
||||
|
||||
_unique_id_suffix = "local_protection"
|
||||
_zcl_attribute: str = "local_protection"
|
||||
_attribute_name = "local_protection"
|
||||
_attr_translation_key = "local_protection"
|
||||
|
||||
|
||||
@ -423,7 +425,7 @@ class InovelliOnOffLEDMode(ZHASwitchConfigurationEntity):
|
||||
"""Inovelli only 1 LED mode control."""
|
||||
|
||||
_unique_id_suffix = "on_off_led_mode"
|
||||
_zcl_attribute: str = "on_off_led_mode"
|
||||
_attribute_name = "on_off_led_mode"
|
||||
_attr_translation_key = "one_led_mode"
|
||||
|
||||
|
||||
@ -434,7 +436,7 @@ class InovelliFirmwareProgressLED(ZHASwitchConfigurationEntity):
|
||||
"""Inovelli firmware progress LED control."""
|
||||
|
||||
_unique_id_suffix = "firmware_progress_led"
|
||||
_zcl_attribute: str = "firmware_progress_led"
|
||||
_attribute_name = "firmware_progress_led"
|
||||
_attr_translation_key = "firmware_progress_led"
|
||||
|
||||
|
||||
@ -445,7 +447,7 @@ class InovelliRelayClickInOnOffMode(ZHASwitchConfigurationEntity):
|
||||
"""Inovelli relay click in on off mode control."""
|
||||
|
||||
_unique_id_suffix = "relay_click_in_on_off_mode"
|
||||
_zcl_attribute: str = "relay_click_in_on_off_mode"
|
||||
_attribute_name = "relay_click_in_on_off_mode"
|
||||
_attr_translation_key = "relay_click_in_on_off_mode"
|
||||
|
||||
|
||||
@ -456,7 +458,7 @@ class InovelliDisableDoubleTapClearNotificationsMode(ZHASwitchConfigurationEntit
|
||||
"""Inovelli disable clear notifications double tap control."""
|
||||
|
||||
_unique_id_suffix = "disable_clear_notifications_double_tap"
|
||||
_zcl_attribute: str = "disable_clear_notifications_double_tap"
|
||||
_attribute_name = "disable_clear_notifications_double_tap"
|
||||
_attr_translation_key = "disable_clear_notifications_double_tap"
|
||||
|
||||
|
||||
@ -467,7 +469,7 @@ class AqaraPetFeederLEDIndicator(ZHASwitchConfigurationEntity):
|
||||
"""Representation of a LED indicator configuration entity."""
|
||||
|
||||
_unique_id_suffix = "disable_led_indicator"
|
||||
_zcl_attribute: str = "disable_led_indicator"
|
||||
_attribute_name = "disable_led_indicator"
|
||||
_attr_translation_key = "led_indicator"
|
||||
_force_inverted = True
|
||||
_attr_icon: str = "mdi:led-on"
|
||||
@ -480,7 +482,7 @@ class AqaraPetFeederChildLock(ZHASwitchConfigurationEntity):
|
||||
"""Representation of a child lock configuration entity."""
|
||||
|
||||
_unique_id_suffix = "child_lock"
|
||||
_zcl_attribute: str = "child_lock"
|
||||
_attribute_name = "child_lock"
|
||||
_attr_translation_key = "child_lock"
|
||||
_attr_icon: str = "mdi:account-lock"
|
||||
|
||||
@ -493,7 +495,7 @@ class TuyaChildLockSwitch(ZHASwitchConfigurationEntity):
|
||||
"""Representation of a child lock configuration entity."""
|
||||
|
||||
_unique_id_suffix = "child_lock"
|
||||
_zcl_attribute: str = "child_lock"
|
||||
_attribute_name = "child_lock"
|
||||
_attr_translation_key = "child_lock"
|
||||
_attr_icon: str = "mdi:account-lock"
|
||||
|
||||
@ -505,7 +507,7 @@ class AqaraThermostatWindowDetection(ZHASwitchConfigurationEntity):
|
||||
"""Representation of an Aqara thermostat window detection configuration entity."""
|
||||
|
||||
_unique_id_suffix = "window_detection"
|
||||
_zcl_attribute: str = "window_detection"
|
||||
_attribute_name = "window_detection"
|
||||
_attr_translation_key = "window_detection"
|
||||
|
||||
|
||||
@ -516,7 +518,7 @@ class AqaraThermostatValveDetection(ZHASwitchConfigurationEntity):
|
||||
"""Representation of an Aqara thermostat valve detection configuration entity."""
|
||||
|
||||
_unique_id_suffix = "valve_detection"
|
||||
_zcl_attribute: str = "valve_detection"
|
||||
_attribute_name = "valve_detection"
|
||||
_attr_translation_key = "valve_detection"
|
||||
|
||||
|
||||
@ -527,7 +529,7 @@ class AqaraThermostatChildLock(ZHASwitchConfigurationEntity):
|
||||
"""Representation of an Aqara thermostat child lock configuration entity."""
|
||||
|
||||
_unique_id_suffix = "child_lock"
|
||||
_zcl_attribute: str = "child_lock"
|
||||
_attribute_name = "child_lock"
|
||||
_attr_translation_key = "child_lock"
|
||||
_attr_icon: str = "mdi:account-lock"
|
||||
|
||||
@ -539,7 +541,7 @@ class AqaraHeartbeatIndicator(ZHASwitchConfigurationEntity):
|
||||
"""Representation of a heartbeat indicator configuration entity for Aqara smoke sensors."""
|
||||
|
||||
_unique_id_suffix = "heartbeat_indicator"
|
||||
_zcl_attribute: str = "heartbeat_indicator"
|
||||
_attribute_name = "heartbeat_indicator"
|
||||
_attr_translation_key = "heartbeat_indicator"
|
||||
_attr_icon: str = "mdi:heart-flash"
|
||||
|
||||
@ -551,7 +553,7 @@ class AqaraLinkageAlarm(ZHASwitchConfigurationEntity):
|
||||
"""Representation of a linkage alarm configuration entity for Aqara smoke sensors."""
|
||||
|
||||
_unique_id_suffix = "linkage_alarm"
|
||||
_zcl_attribute: str = "linkage_alarm"
|
||||
_attribute_name = "linkage_alarm"
|
||||
_attr_translation_key = "linkage_alarm"
|
||||
_attr_icon: str = "mdi:shield-link-variant"
|
||||
|
||||
@ -563,7 +565,7 @@ class AqaraBuzzerManualMute(ZHASwitchConfigurationEntity):
|
||||
"""Representation of a buzzer manual mute configuration entity for Aqara smoke sensors."""
|
||||
|
||||
_unique_id_suffix = "buzzer_manual_mute"
|
||||
_zcl_attribute: str = "buzzer_manual_mute"
|
||||
_attribute_name = "buzzer_manual_mute"
|
||||
_attr_translation_key = "buzzer_manual_mute"
|
||||
_attr_icon: str = "mdi:volume-off"
|
||||
|
||||
@ -575,6 +577,6 @@ class AqaraBuzzerManualAlarm(ZHASwitchConfigurationEntity):
|
||||
"""Representation of a buzzer manual mute configuration entity for Aqara smoke sensors."""
|
||||
|
||||
_unique_id_suffix = "buzzer_manual_alarm"
|
||||
_zcl_attribute: str = "buzzer_manual_alarm"
|
||||
_attribute_name = "buzzer_manual_alarm"
|
||||
_attr_translation_key = "buzzer_manual_alarm"
|
||||
_attr_icon: str = "mdi:bullhorn"
|
||||
|
Loading…
x
Reference in New Issue
Block a user