mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Small cleanups to ESPHome (#107924)
- Remove unused variables - Remove unneeded static info lookups
This commit is contained in:
parent
b1d0c6a4f1
commit
5a198e05ad
@ -89,17 +89,17 @@ class EsphomeAlarmControlPanel(
|
|||||||
super()._on_static_info_update(static_info)
|
super()._on_static_info_update(static_info)
|
||||||
static_info = self._static_info
|
static_info = self._static_info
|
||||||
feature = 0
|
feature = 0
|
||||||
if self._static_info.supported_features & EspHomeACPFeatures.ARM_HOME:
|
if static_info.supported_features & EspHomeACPFeatures.ARM_HOME:
|
||||||
feature |= AlarmControlPanelEntityFeature.ARM_HOME
|
feature |= AlarmControlPanelEntityFeature.ARM_HOME
|
||||||
if self._static_info.supported_features & EspHomeACPFeatures.ARM_AWAY:
|
if static_info.supported_features & EspHomeACPFeatures.ARM_AWAY:
|
||||||
feature |= AlarmControlPanelEntityFeature.ARM_AWAY
|
feature |= AlarmControlPanelEntityFeature.ARM_AWAY
|
||||||
if self._static_info.supported_features & EspHomeACPFeatures.ARM_NIGHT:
|
if static_info.supported_features & EspHomeACPFeatures.ARM_NIGHT:
|
||||||
feature |= AlarmControlPanelEntityFeature.ARM_NIGHT
|
feature |= AlarmControlPanelEntityFeature.ARM_NIGHT
|
||||||
if self._static_info.supported_features & EspHomeACPFeatures.TRIGGER:
|
if static_info.supported_features & EspHomeACPFeatures.TRIGGER:
|
||||||
feature |= AlarmControlPanelEntityFeature.TRIGGER
|
feature |= AlarmControlPanelEntityFeature.TRIGGER
|
||||||
if self._static_info.supported_features & EspHomeACPFeatures.ARM_CUSTOM_BYPASS:
|
if static_info.supported_features & EspHomeACPFeatures.ARM_CUSTOM_BYPASS:
|
||||||
feature |= AlarmControlPanelEntityFeature.ARM_CUSTOM_BYPASS
|
feature |= AlarmControlPanelEntityFeature.ARM_CUSTOM_BYPASS
|
||||||
if self._static_info.supported_features & EspHomeACPFeatures.ARM_VACATION:
|
if static_info.supported_features & EspHomeACPFeatures.ARM_VACATION:
|
||||||
feature |= AlarmControlPanelEntityFeature.ARM_VACATION
|
feature |= AlarmControlPanelEntityFeature.ARM_VACATION
|
||||||
self._attr_supported_features = AlarmControlPanelEntityFeature(feature)
|
self._attr_supported_features = AlarmControlPanelEntityFeature(feature)
|
||||||
self._attr_code_format = (
|
self._attr_code_format = (
|
||||||
|
@ -167,11 +167,11 @@ class EsphomeClimateEntity(EsphomeEntity[ClimateInfo, ClimateState], ClimateEnti
|
|||||||
self._attr_min_humidity = round(static_info.visual_min_humidity)
|
self._attr_min_humidity = round(static_info.visual_min_humidity)
|
||||||
self._attr_max_humidity = round(static_info.visual_max_humidity)
|
self._attr_max_humidity = round(static_info.visual_max_humidity)
|
||||||
features = ClimateEntityFeature(0)
|
features = ClimateEntityFeature(0)
|
||||||
if self._static_info.supports_two_point_target_temperature:
|
if static_info.supports_two_point_target_temperature:
|
||||||
features |= ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
|
features |= ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
|
||||||
else:
|
else:
|
||||||
features |= ClimateEntityFeature.TARGET_TEMPERATURE
|
features |= ClimateEntityFeature.TARGET_TEMPERATURE
|
||||||
if self._static_info.supports_target_humidity:
|
if static_info.supports_target_humidity:
|
||||||
features |= ClimateEntityFeature.TARGET_HUMIDITY
|
features |= ClimateEntityFeature.TARGET_HUMIDITY
|
||||||
if self.preset_modes:
|
if self.preset_modes:
|
||||||
features |= ClimateEntityFeature.PRESET_MODE
|
features |= ClimateEntityFeature.PRESET_MODE
|
||||||
|
@ -145,7 +145,6 @@ class EsphomeEntity(Entity, Generic[_InfoT, _StateT]):
|
|||||||
state_type: type[_StateT],
|
state_type: type[_StateT],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
|
|
||||||
self._entry_data = entry_data
|
self._entry_data = entry_data
|
||||||
self._on_entry_data_changed()
|
self._on_entry_data_changed()
|
||||||
self._key = entity_info.key
|
self._key = entity_info.key
|
||||||
@ -157,7 +156,6 @@ class EsphomeEntity(Entity, Generic[_InfoT, _StateT]):
|
|||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
connections={(dr.CONNECTION_NETWORK_MAC, device_info.mac_address)}
|
connections={(dr.CONNECTION_NETWORK_MAC, device_info.mac_address)}
|
||||||
)
|
)
|
||||||
self._entry_id = entry_data.entry_id
|
|
||||||
#
|
#
|
||||||
# If `friendly_name` is set, we use the Friendly naming rules, if
|
# If `friendly_name` is set, we use the Friendly naming rules, if
|
||||||
# `friendly_name` is not set we make an exception to the naming rules for
|
# `friendly_name` is not set we make an exception to the naming rules for
|
||||||
@ -183,10 +181,11 @@ class EsphomeEntity(Entity, Generic[_InfoT, _StateT]):
|
|||||||
entry_data = self._entry_data
|
entry_data = self._entry_data
|
||||||
hass = self.hass
|
hass = self.hass
|
||||||
key = self._key
|
key = self._key
|
||||||
|
static_info = self._static_info
|
||||||
|
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
entry_data.async_register_key_static_info_remove_callback(
|
entry_data.async_register_key_static_info_remove_callback(
|
||||||
self._static_info,
|
static_info,
|
||||||
functools.partial(self.async_remove, force_remove=True),
|
functools.partial(self.async_remove, force_remove=True),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -204,7 +203,7 @@ class EsphomeEntity(Entity, Generic[_InfoT, _StateT]):
|
|||||||
)
|
)
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
entry_data.async_register_key_static_info_updated_callback(
|
entry_data.async_register_key_static_info_updated_callback(
|
||||||
self._static_info, self._on_static_info_update
|
static_info, self._on_static_info_update
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self._update_state_from_entry_data()
|
self._update_state_from_entry_data()
|
||||||
@ -236,12 +235,10 @@ class EsphomeEntity(Entity, Generic[_InfoT, _StateT]):
|
|||||||
@callback
|
@callback
|
||||||
def _update_state_from_entry_data(self) -> None:
|
def _update_state_from_entry_data(self) -> None:
|
||||||
"""Update state from entry data."""
|
"""Update state from entry data."""
|
||||||
|
|
||||||
state = self._entry_data.state
|
state = self._entry_data.state
|
||||||
key = self._key
|
key = self._key
|
||||||
state_type = self._state_type
|
state_type = self._state_type
|
||||||
has_state = key in state[state_type]
|
if has_state := key in state[state_type]:
|
||||||
if has_state:
|
|
||||||
self._state = cast(_StateT, state[state_type][key])
|
self._state = cast(_StateT, state[state_type][key])
|
||||||
self._has_state = has_state
|
self._has_state = has_state
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ class EsphomeNumber(EsphomeEntity[NumberInfo, NumberState], NumberEntity):
|
|||||||
super()._on_static_info_update(static_info)
|
super()._on_static_info_update(static_info)
|
||||||
static_info = self._static_info
|
static_info = self._static_info
|
||||||
self._attr_device_class = try_parse_enum(
|
self._attr_device_class = try_parse_enum(
|
||||||
NumberDeviceClass, self._static_info.device_class
|
NumberDeviceClass, static_info.device_class
|
||||||
)
|
)
|
||||||
self._attr_native_min_value = static_info.min_value
|
self._attr_native_min_value = static_info.min_value
|
||||||
self._attr_native_max_value = static_info.max_value
|
self._attr_native_max_value = static_info.max_value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user