mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Cleanup access to supported features (#82274)
This commit is contained in:
parent
3dba9c4695
commit
0c887eab87
@ -143,13 +143,12 @@ class HumidifierEntity(ToggleEntity):
|
|||||||
@property
|
@property
|
||||||
def capability_attributes(self) -> dict[str, Any]:
|
def capability_attributes(self) -> dict[str, Any]:
|
||||||
"""Return capability attributes."""
|
"""Return capability attributes."""
|
||||||
supported_features = self.supported_features or 0
|
|
||||||
data: dict[str, int | list[str] | None] = {
|
data: dict[str, int | list[str] | None] = {
|
||||||
ATTR_MIN_HUMIDITY: self.min_humidity,
|
ATTR_MIN_HUMIDITY: self.min_humidity,
|
||||||
ATTR_MAX_HUMIDITY: self.max_humidity,
|
ATTR_MAX_HUMIDITY: self.max_humidity,
|
||||||
}
|
}
|
||||||
|
|
||||||
if supported_features & HumidifierEntityFeature.MODES:
|
if self.supported_features & HumidifierEntityFeature.MODES:
|
||||||
data[ATTR_AVAILABLE_MODES] = self.available_modes
|
data[ATTR_AVAILABLE_MODES] = self.available_modes
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@ -167,13 +166,12 @@ class HumidifierEntity(ToggleEntity):
|
|||||||
@property
|
@property
|
||||||
def state_attributes(self) -> dict[str, Any]:
|
def state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return the optional state attributes."""
|
"""Return the optional state attributes."""
|
||||||
supported_features = self.supported_features or 0
|
|
||||||
data: dict[str, int | str | None] = {}
|
data: dict[str, int | str | None] = {}
|
||||||
|
|
||||||
if self.target_humidity is not None:
|
if self.target_humidity is not None:
|
||||||
data[ATTR_HUMIDITY] = self.target_humidity
|
data[ATTR_HUMIDITY] = self.target_humidity
|
||||||
|
|
||||||
if supported_features & HumidifierEntityFeature.MODES:
|
if self.supported_features & HumidifierEntityFeature.MODES:
|
||||||
data[ATTR_MODE] = self.mode
|
data[ATTR_MODE] = self.mode
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
@ -1000,15 +1000,14 @@ class MediaPlayerEntity(Entity):
|
|||||||
@property
|
@property
|
||||||
def capability_attributes(self) -> dict[str, Any]:
|
def capability_attributes(self) -> dict[str, Any]:
|
||||||
"""Return capability attributes."""
|
"""Return capability attributes."""
|
||||||
supported_features = self.supported_features or 0
|
|
||||||
data: dict[str, Any] = {}
|
data: dict[str, Any] = {}
|
||||||
|
|
||||||
if supported_features & MediaPlayerEntityFeature.SELECT_SOURCE and (
|
if self.supported_features & MediaPlayerEntityFeature.SELECT_SOURCE and (
|
||||||
source_list := self.source_list
|
source_list := self.source_list
|
||||||
):
|
):
|
||||||
data[ATTR_INPUT_SOURCE_LIST] = source_list
|
data[ATTR_INPUT_SOURCE_LIST] = source_list
|
||||||
|
|
||||||
if supported_features & MediaPlayerEntityFeature.SELECT_SOUND_MODE and (
|
if self.supported_features & MediaPlayerEntityFeature.SELECT_SOUND_MODE and (
|
||||||
sound_mode_list := self.sound_mode_list
|
sound_mode_list := self.sound_mode_list
|
||||||
):
|
):
|
||||||
data[ATTR_SOUND_MODE_LIST] = sound_mode_list
|
data[ATTR_SOUND_MODE_LIST] = sound_mode_list
|
||||||
|
@ -64,9 +64,8 @@ def process_turn_on_params(
|
|||||||
|
|
||||||
Filters out unsupported params and validates the rest.
|
Filters out unsupported params and validates the rest.
|
||||||
"""
|
"""
|
||||||
supported_features = siren.supported_features or 0
|
|
||||||
|
|
||||||
if not supported_features & SirenEntityFeature.TONES:
|
if not siren.supported_features & SirenEntityFeature.TONES:
|
||||||
params.pop(ATTR_TONE, None)
|
params.pop(ATTR_TONE, None)
|
||||||
elif (tone := params.get(ATTR_TONE)) is not None:
|
elif (tone := params.get(ATTR_TONE)) is not None:
|
||||||
# Raise an exception if the specified tone isn't available
|
# Raise an exception if the specified tone isn't available
|
||||||
@ -92,9 +91,9 @@ def process_turn_on_params(
|
|||||||
key for key, value in siren.available_tones.items() if value == tone
|
key for key, value in siren.available_tones.items() if value == tone
|
||||||
)
|
)
|
||||||
|
|
||||||
if not supported_features & SirenEntityFeature.DURATION:
|
if not siren.supported_features & SirenEntityFeature.DURATION:
|
||||||
params.pop(ATTR_DURATION, None)
|
params.pop(ATTR_DURATION, None)
|
||||||
if not supported_features & SirenEntityFeature.VOLUME_SET:
|
if not siren.supported_features & SirenEntityFeature.VOLUME_SET:
|
||||||
params.pop(ATTR_VOLUME_LEVEL, None)
|
params.pop(ATTR_VOLUME_LEVEL, None)
|
||||||
|
|
||||||
return params
|
return params
|
||||||
@ -169,10 +168,8 @@ class SirenEntity(ToggleEntity):
|
|||||||
@property
|
@property
|
||||||
def capability_attributes(self) -> dict[str, Any] | None:
|
def capability_attributes(self) -> dict[str, Any] | None:
|
||||||
"""Return capability attributes."""
|
"""Return capability attributes."""
|
||||||
supported_features = self.supported_features or 0
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
supported_features & SirenEntityFeature.TONES
|
self.supported_features & SirenEntityFeature.TONES
|
||||||
and self.available_tones is not None
|
and self.available_tones is not None
|
||||||
):
|
):
|
||||||
return {ATTR_AVAILABLE_TONES: self.available_tones}
|
return {ATTR_AVAILABLE_TONES: self.available_tones}
|
||||||
|
@ -191,8 +191,6 @@ class WaterHeaterEntity(Entity):
|
|||||||
@property
|
@property
|
||||||
def capability_attributes(self) -> Mapping[str, Any]:
|
def capability_attributes(self) -> Mapping[str, Any]:
|
||||||
"""Return capability attributes."""
|
"""Return capability attributes."""
|
||||||
supported_features = self.supported_features or 0
|
|
||||||
|
|
||||||
data: dict[str, Any] = {
|
data: dict[str, Any] = {
|
||||||
ATTR_MIN_TEMP: show_temp(
|
ATTR_MIN_TEMP: show_temp(
|
||||||
self.hass, self.min_temp, self.temperature_unit, self.precision
|
self.hass, self.min_temp, self.temperature_unit, self.precision
|
||||||
@ -202,7 +200,7 @@ class WaterHeaterEntity(Entity):
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
if supported_features & WaterHeaterEntityFeature.OPERATION_MODE:
|
if self.supported_features & WaterHeaterEntityFeature.OPERATION_MODE:
|
||||||
data[ATTR_OPERATION_LIST] = self.operation_list
|
data[ATTR_OPERATION_LIST] = self.operation_list
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@ -238,12 +236,10 @@ class WaterHeaterEntity(Entity):
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
supported_features = self.supported_features or 0
|
if self.supported_features & WaterHeaterEntityFeature.OPERATION_MODE:
|
||||||
|
|
||||||
if supported_features & WaterHeaterEntityFeature.OPERATION_MODE:
|
|
||||||
data[ATTR_OPERATION_MODE] = self.current_operation
|
data[ATTR_OPERATION_MODE] = self.current_operation
|
||||||
|
|
||||||
if supported_features & WaterHeaterEntityFeature.AWAY_MODE:
|
if self.supported_features & WaterHeaterEntityFeature.AWAY_MODE:
|
||||||
is_away = self.is_away_mode_on
|
is_away = self.is_away_mode_on
|
||||||
data[ATTR_AWAY_MODE] = STATE_ON if is_away else STATE_OFF
|
data[ATTR_AWAY_MODE] = STATE_ON if is_away else STATE_OFF
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user