Standardize _select_attr in ZCLEnumSelectEntity (#102454)

This commit is contained in:
Caius-Bonus 2023-10-22 16:18:38 +02:00 committed by GitHub
parent 8bfd418c3e
commit 51f989c57a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -155,7 +155,7 @@ class ZHADefaultStrobeSelectEntity(ZHANonZCLSelectEntity):
class ZCLEnumSelectEntity(ZhaEntity, SelectEntity): class ZCLEnumSelectEntity(ZhaEntity, SelectEntity):
"""Representation of a ZHA ZCL enum select entity.""" """Representation of a ZHA ZCL enum select entity."""
_select_attr: str _attribute_name: str
_attr_entity_category = EntityCategory.CONFIG _attr_entity_category = EntityCategory.CONFIG
_enum: type[Enum] _enum: type[Enum]
@ -173,13 +173,13 @@ class ZCLEnumSelectEntity(ZhaEntity, SelectEntity):
""" """
cluster_handler = cluster_handlers[0] cluster_handler = cluster_handlers[0]
if ( if (
cls._select_attr in cluster_handler.cluster.unsupported_attributes cls._attribute_name in cluster_handler.cluster.unsupported_attributes
or cls._select_attr not in cluster_handler.cluster.attributes_by_name or cls._attribute_name not in cluster_handler.cluster.attributes_by_name
or cluster_handler.cluster.get(cls._select_attr) is None or cluster_handler.cluster.get(cls._attribute_name) is None
): ):
_LOGGER.debug( _LOGGER.debug(
"%s is not supported - skipping %s entity creation", "%s is not supported - skipping %s entity creation",
cls._select_attr, cls._attribute_name,
cls.__name__, cls.__name__,
) )
return None return None
@ -201,7 +201,7 @@ class ZCLEnumSelectEntity(ZhaEntity, SelectEntity):
@property @property
def current_option(self) -> str | None: def current_option(self) -> str | None:
"""Return the selected entity option to represent the entity state.""" """Return the selected entity option to represent the entity state."""
option = self._cluster_handler.cluster.get(self._select_attr) option = self._cluster_handler.cluster.get(self._attribute_name)
if option is None: if option is None:
return None return None
option = self._enum(option) option = self._enum(option)
@ -210,7 +210,7 @@ class ZCLEnumSelectEntity(ZhaEntity, SelectEntity):
async def async_select_option(self, option: str) -> None: async def async_select_option(self, option: str) -> None:
"""Change the selected option.""" """Change the selected option."""
await self._cluster_handler.write_attributes_safe( await self._cluster_handler.write_attributes_safe(
{self._select_attr: self._enum[option.replace(" ", "_")]} {self._attribute_name: self._enum[option.replace(" ", "_")]}
) )
self.async_write_ha_state() self.async_write_ha_state()
@ -232,7 +232,7 @@ class ZHAStartupOnOffSelectEntity(ZCLEnumSelectEntity):
"""Representation of a ZHA startup onoff select entity.""" """Representation of a ZHA startup onoff select entity."""
_unique_id_suffix = OnOff.StartUpOnOff.__name__ _unique_id_suffix = OnOff.StartUpOnOff.__name__
_select_attr = "start_up_on_off" _attribute_name = "start_up_on_off"
_enum = OnOff.StartUpOnOff _enum = OnOff.StartUpOnOff
_attr_translation_key: str = "start_up_on_off" _attr_translation_key: str = "start_up_on_off"
@ -274,7 +274,7 @@ class TuyaPowerOnStateSelectEntity(ZCLEnumSelectEntity):
"""Representation of a ZHA power on state select entity.""" """Representation of a ZHA power on state select entity."""
_unique_id_suffix = "power_on_state" _unique_id_suffix = "power_on_state"
_select_attr = "power_on_state" _attribute_name = "power_on_state"
_enum = TuyaPowerOnState _enum = TuyaPowerOnState
_attr_translation_key: str = "power_on_state" _attr_translation_key: str = "power_on_state"
@ -295,7 +295,7 @@ class TuyaBacklightModeSelectEntity(ZCLEnumSelectEntity):
"""Representation of a ZHA backlight mode select entity.""" """Representation of a ZHA backlight mode select entity."""
_unique_id_suffix = "backlight_mode" _unique_id_suffix = "backlight_mode"
_select_attr = "backlight_mode" _attribute_name = "backlight_mode"
_enum = TuyaBacklightMode _enum = TuyaBacklightMode
_attr_translation_key: str = "backlight_mode" _attr_translation_key: str = "backlight_mode"
@ -334,7 +334,7 @@ class MoesBacklightModeSelectEntity(ZCLEnumSelectEntity):
"""Moes devices have a different backlight mode select options.""" """Moes devices have a different backlight mode select options."""
_unique_id_suffix = "backlight_mode" _unique_id_suffix = "backlight_mode"
_select_attr = "backlight_mode" _attribute_name = "backlight_mode"
_enum = MoesBacklightMode _enum = MoesBacklightMode
_attr_translation_key: str = "backlight_mode" _attr_translation_key: str = "backlight_mode"
@ -355,7 +355,7 @@ class AqaraMotionSensitivity(ZCLEnumSelectEntity):
"""Representation of a ZHA motion sensitivity configuration entity.""" """Representation of a ZHA motion sensitivity configuration entity."""
_unique_id_suffix = "motion_sensitivity" _unique_id_suffix = "motion_sensitivity"
_select_attr = "motion_sensitivity" _attribute_name = "motion_sensitivity"
_enum = AqaraMotionSensitivities _enum = AqaraMotionSensitivities
_attr_translation_key: str = "motion_sensitivity" _attr_translation_key: str = "motion_sensitivity"
@ -377,7 +377,7 @@ class HueV1MotionSensitivity(ZCLEnumSelectEntity):
"""Representation of a ZHA motion sensitivity configuration entity.""" """Representation of a ZHA motion sensitivity configuration entity."""
_unique_id_suffix = "motion_sensitivity" _unique_id_suffix = "motion_sensitivity"
_select_attr = "sensitivity" _attribute_name = "sensitivity"
_enum = HueV1MotionSensitivities _enum = HueV1MotionSensitivities
_attr_translation_key: str = "motion_sensitivity" _attr_translation_key: str = "motion_sensitivity"
@ -401,7 +401,7 @@ class HueV2MotionSensitivity(ZCLEnumSelectEntity):
"""Representation of a ZHA motion sensitivity configuration entity.""" """Representation of a ZHA motion sensitivity configuration entity."""
_unique_id_suffix = "motion_sensitivity" _unique_id_suffix = "motion_sensitivity"
_select_attr = "sensitivity" _attribute_name = "sensitivity"
_enum = HueV2MotionSensitivities _enum = HueV2MotionSensitivities
_attr_translation_key: str = "motion_sensitivity" _attr_translation_key: str = "motion_sensitivity"
@ -420,7 +420,7 @@ class AqaraMonitoringMode(ZCLEnumSelectEntity):
"""Representation of a ZHA monitoring mode configuration entity.""" """Representation of a ZHA monitoring mode configuration entity."""
_unique_id_suffix = "monitoring_mode" _unique_id_suffix = "monitoring_mode"
_select_attr = "monitoring_mode" _attribute_name = "monitoring_mode"
_enum = AqaraMonitoringModess _enum = AqaraMonitoringModess
_attr_translation_key: str = "monitoring_mode" _attr_translation_key: str = "monitoring_mode"
@ -440,7 +440,7 @@ class AqaraApproachDistance(ZCLEnumSelectEntity):
"""Representation of a ZHA approach distance configuration entity.""" """Representation of a ZHA approach distance configuration entity."""
_unique_id_suffix = "approach_distance" _unique_id_suffix = "approach_distance"
_select_attr = "approach_distance" _attribute_name = "approach_distance"
_enum = AqaraApproachDistances _enum = AqaraApproachDistances
_attr_translation_key: str = "approach_distance" _attr_translation_key: str = "approach_distance"
@ -459,7 +459,7 @@ class AqaraCurtainMode(ZCLEnumSelectEntity):
"""Representation of a ZHA curtain mode configuration entity.""" """Representation of a ZHA curtain mode configuration entity."""
_unique_id_suffix = "window_covering_mode" _unique_id_suffix = "window_covering_mode"
_select_attr = "window_covering_mode" _attribute_name = "window_covering_mode"
_enum = AqaraE1ReverseDirection _enum = AqaraE1ReverseDirection
_attr_translation_key: str = "window_covering_mode" _attr_translation_key: str = "window_covering_mode"
@ -478,7 +478,7 @@ class InovelliOutputModeEntity(ZCLEnumSelectEntity):
"""Inovelli output mode control.""" """Inovelli output mode control."""
_unique_id_suffix = "output_mode" _unique_id_suffix = "output_mode"
_select_attr = "output_mode" _attribute_name = "output_mode"
_enum = InovelliOutputMode _enum = InovelliOutputMode
_attr_translation_key: str = "output_mode" _attr_translation_key: str = "output_mode"
@ -499,7 +499,7 @@ class InovelliSwitchTypeEntity(ZCLEnumSelectEntity):
"""Inovelli switch type control.""" """Inovelli switch type control."""
_unique_id_suffix = "switch_type" _unique_id_suffix = "switch_type"
_select_attr = "switch_type" _attribute_name = "switch_type"
_enum = InovelliSwitchType _enum = InovelliSwitchType
_attr_translation_key: str = "switch_type" _attr_translation_key: str = "switch_type"
@ -518,7 +518,7 @@ class InovelliLedScalingModeEntity(ZCLEnumSelectEntity):
"""Inovelli led mode control.""" """Inovelli led mode control."""
_unique_id_suffix = "led_scaling_mode" _unique_id_suffix = "led_scaling_mode"
_select_attr = "led_scaling_mode" _attribute_name = "led_scaling_mode"
_enum = InovelliLedScalingMode _enum = InovelliLedScalingMode
_attr_translation_key: str = "led_scaling_mode" _attr_translation_key: str = "led_scaling_mode"
@ -537,7 +537,7 @@ class InovelliNonNeutralOutputEntity(ZCLEnumSelectEntity):
"""Inovelli non neutral output control.""" """Inovelli non neutral output control."""
_unique_id_suffix = "increased_non_neutral_output" _unique_id_suffix = "increased_non_neutral_output"
_select_attr = "increased_non_neutral_output" _attribute_name = "increased_non_neutral_output"
_enum = InovelliNonNeutralOutput _enum = InovelliNonNeutralOutput
_attr_translation_key: str = "increased_non_neutral_output" _attr_translation_key: str = "increased_non_neutral_output"
@ -556,7 +556,7 @@ class AqaraPetFeederMode(ZCLEnumSelectEntity):
"""Representation of an Aqara pet feeder mode configuration entity.""" """Representation of an Aqara pet feeder mode configuration entity."""
_unique_id_suffix = "feeding_mode" _unique_id_suffix = "feeding_mode"
_select_attr = "feeding_mode" _attribute_name = "feeding_mode"
_enum = AqaraFeedingMode _enum = AqaraFeedingMode
_attr_translation_key: str = "feeding_mode" _attr_translation_key: str = "feeding_mode"
_attr_icon: str = "mdi:wrench-clock" _attr_icon: str = "mdi:wrench-clock"
@ -577,6 +577,6 @@ class AqaraThermostatPreset(ZCLEnumSelectEntity):
"""Representation of an Aqara thermostat preset configuration entity.""" """Representation of an Aqara thermostat preset configuration entity."""
_unique_id_suffix = "preset" _unique_id_suffix = "preset"
_select_attr = "preset" _attribute_name = "preset"
_enum = AqaraThermostatPresetMode _enum = AqaraThermostatPresetMode
_attr_translation_key: str = "preset" _attr_translation_key: str = "preset"