Return attribute dict directly without temporary variable v2 (#41271)
This commit is contained in:
parent
33e69fe4bf
commit
513f03eb1f
27 changed files with 90 additions and 124 deletions
|
@ -209,10 +209,7 @@ class DeconzBaseLight(DeconzDevice, LightEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the device state attributes."""
|
||||
attributes = {}
|
||||
attributes["is_deconz_group"] = self._device.type == "LightGroup"
|
||||
|
||||
return attributes
|
||||
return {"is_deconz_group": self._device.type == "LightGroup"}
|
||||
|
||||
|
||||
class DeconzLight(DeconzBaseLight):
|
||||
|
|
|
@ -308,14 +308,13 @@ class DenonDevice(MediaPlayerEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return device specific state attributes."""
|
||||
attributes = {}
|
||||
if (
|
||||
self._sound_mode_raw is not None
|
||||
and self._sound_mode_support
|
||||
and self._power == "ON"
|
||||
):
|
||||
attributes[ATTR_SOUND_MODE_RAW] = self._sound_mode_raw
|
||||
return attributes
|
||||
return {ATTR_SOUND_MODE_RAW: self._sound_mode_raw}
|
||||
return {}
|
||||
|
||||
def media_play_pause(self):
|
||||
"""Play or pause the media player."""
|
||||
|
|
|
@ -213,8 +213,7 @@ class DerivativeSensor(RestoreEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the sensor."""
|
||||
state_attr = {ATTR_SOURCE_ID: self._sensor_source_id}
|
||||
return state_attr
|
||||
return {ATTR_SOURCE_ID: self._sensor_source_id}
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
|
|
@ -126,14 +126,14 @@ class DIRECTVMediaPlayer(DIRECTVEntity, MediaPlayerEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return device specific state attributes."""
|
||||
attributes = {}
|
||||
if not self._is_standby:
|
||||
attributes[ATTR_MEDIA_CURRENTLY_RECORDING] = self.media_currently_recording
|
||||
attributes[ATTR_MEDIA_RATING] = self.media_rating
|
||||
attributes[ATTR_MEDIA_RECORDED] = self.media_recorded
|
||||
attributes[ATTR_MEDIA_START_TIME] = self.media_start_time
|
||||
|
||||
return attributes
|
||||
return {
|
||||
ATTR_MEDIA_CURRENTLY_RECORDING: self.media_currently_recording,
|
||||
ATTR_MEDIA_RATING: self.media_rating,
|
||||
ATTR_MEDIA_RECORDED: self.media_recorded,
|
||||
ATTR_MEDIA_START_TIME: self.media_start_time,
|
||||
}
|
||||
return {}
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -112,11 +112,11 @@ class EightHeatSensor(EightSleepHeatEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return device state attributes."""
|
||||
state_attr = {ATTR_TARGET_HEAT: self._usrobj.target_heating_level}
|
||||
state_attr[ATTR_ACTIVE_HEAT] = self._usrobj.now_heating
|
||||
state_attr[ATTR_DURATION_HEAT] = self._usrobj.heating_remaining
|
||||
|
||||
return state_attr
|
||||
return {
|
||||
ATTR_TARGET_HEAT: self._usrobj.target_heating_level,
|
||||
ATTR_ACTIVE_HEAT: self._usrobj.now_heating,
|
||||
ATTR_DURATION_HEAT: self._usrobj.heating_remaining,
|
||||
}
|
||||
|
||||
|
||||
class EightUserSensor(EightSleepUserEntity):
|
||||
|
|
|
@ -253,17 +253,13 @@ class Enigma2Device(MediaPlayerEntity):
|
|||
currservice_begin: is in the format '21:00'.
|
||||
currservice_end: is in the format '21:00'.
|
||||
"""
|
||||
attributes = {}
|
||||
if not self.e2_box.in_standby:
|
||||
attributes[ATTR_MEDIA_CURRENTLY_RECORDING] = self.e2_box.status_info[
|
||||
"isRecording"
|
||||
]
|
||||
attributes[ATTR_MEDIA_DESCRIPTION] = self.e2_box.status_info[
|
||||
if self.e2_box.in_standby:
|
||||
return {}
|
||||
return {
|
||||
ATTR_MEDIA_CURRENTLY_RECORDING: self.e2_box.status_info["isRecording"],
|
||||
ATTR_MEDIA_DESCRIPTION: self.e2_box.status_info[
|
||||
"currservice_fulldescription"
|
||||
]
|
||||
attributes[ATTR_MEDIA_START_TIME] = self.e2_box.status_info[
|
||||
"currservice_begin"
|
||||
]
|
||||
attributes[ATTR_MEDIA_END_TIME] = self.e2_box.status_info["currservice_end"]
|
||||
|
||||
return attributes
|
||||
],
|
||||
ATTR_MEDIA_START_TIME: self.e2_box.status_info["currservice_begin"],
|
||||
ATTR_MEDIA_END_TIME: self.e2_box.status_info["currservice_end"],
|
||||
}
|
||||
|
|
|
@ -235,7 +235,6 @@ class EpsonProjector(MediaPlayerEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return device specific state attributes."""
|
||||
attributes = {}
|
||||
if self._cmode is not None:
|
||||
attributes[ATTR_CMODE] = self._cmode
|
||||
return attributes
|
||||
return {ATTR_CMODE: self._cmode}
|
||||
return {}
|
||||
|
|
|
@ -319,8 +319,7 @@ class SensorFilter(Entity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the sensor."""
|
||||
state_attr = {ATTR_ENTITY_ID: self._entity}
|
||||
return state_attr
|
||||
return {ATTR_ENTITY_ID: self._entity}
|
||||
|
||||
|
||||
class FilterState:
|
||||
|
|
|
@ -36,12 +36,13 @@ class FloPendingAlertsBinarySensor(FloEntity, BinarySensorEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
attr = {}
|
||||
if self._device.has_alerts:
|
||||
attr["info"] = self._device.pending_info_alerts_count
|
||||
attr["warning"] = self._device.pending_warning_alerts_count
|
||||
attr["critical"] = self._device.pending_critical_alerts_count
|
||||
return attr
|
||||
return {
|
||||
"info": self._device.pending_info_alerts_count,
|
||||
"warning": self._device.pending_warning_alerts_count,
|
||||
"critical": self._device.pending_critical_alerts_count,
|
||||
}
|
||||
return {}
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
|
|
|
@ -121,14 +121,13 @@ class GarminConnectSensor(Entity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return attributes for sensor."""
|
||||
attributes = {}
|
||||
if self._data.data:
|
||||
attributes = {
|
||||
return {
|
||||
"source": self._data.data["source"],
|
||||
"last_synced": self._data.data["lastSyncTimestampGMT"],
|
||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
||||
}
|
||||
return attributes
|
||||
return {}
|
||||
|
||||
@property
|
||||
def device_info(self) -> Dict[str, Any]:
|
||||
|
|
|
@ -203,7 +203,6 @@ class GeoJsonLocationEvent(GeolocationEvent):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the device state attributes."""
|
||||
attributes = {}
|
||||
if self._external_id:
|
||||
attributes[ATTR_EXTERNAL_ID] = self._external_id
|
||||
return attributes
|
||||
return {ATTR_EXTERNAL_ID: self._external_id}
|
||||
return {}
|
||||
|
|
|
@ -110,10 +110,8 @@ class HomeKitAlarmControlPanelEntity(HomeKitEntity, AlarmControlPanelEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the optional state attributes."""
|
||||
attributes = {}
|
||||
|
||||
battery_level = self.service.value(CharacteristicsTypes.BATTERY_LEVEL)
|
||||
if battery_level:
|
||||
attributes[ATTR_BATTERY_LEVEL] = battery_level
|
||||
|
||||
return attributes
|
||||
if battery_level:
|
||||
return {ATTR_BATTERY_LEVEL: battery_level}
|
||||
return {}
|
||||
|
|
|
@ -117,15 +117,13 @@ class HomeKitGarageDoorCover(HomeKitEntity, CoverEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the optional state attributes."""
|
||||
attributes = {}
|
||||
|
||||
obstruction_detected = self.service.value(
|
||||
CharacteristicsTypes.OBSTRUCTION_DETECTED
|
||||
)
|
||||
if obstruction_detected:
|
||||
attributes["obstruction-detected"] = obstruction_detected
|
||||
return {"obstruction-detected": obstruction_detected}
|
||||
|
||||
return attributes
|
||||
return {}
|
||||
|
||||
|
||||
class HomeKitWindowCover(HomeKitEntity, CoverEntity):
|
||||
|
@ -249,12 +247,9 @@ class HomeKitWindowCover(HomeKitEntity, CoverEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the optional state attributes."""
|
||||
attributes = {}
|
||||
|
||||
obstruction_detected = self.service.value(
|
||||
CharacteristicsTypes.OBSTRUCTION_DETECTED
|
||||
)
|
||||
if obstruction_detected:
|
||||
attributes["obstruction-detected"] = obstruction_detected
|
||||
|
||||
return attributes
|
||||
return {"obstruction-detected": obstruction_detected}
|
||||
return {}
|
||||
|
|
|
@ -458,7 +458,6 @@ class HueLight(CoordinatorEntity, LightEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the device state attributes."""
|
||||
attributes = {}
|
||||
if self.is_group:
|
||||
attributes[ATTR_IS_HUE_GROUP] = self.is_group
|
||||
return attributes
|
||||
return {ATTR_IS_HUE_GROUP: self.is_group}
|
||||
return {}
|
||||
|
|
|
@ -203,8 +203,7 @@ class IntegrationSensor(RestoreEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the sensor."""
|
||||
state_attr = {ATTR_SOURCE_ID: self._sensor_source_id}
|
||||
return state_attr
|
||||
return {ATTR_SOURCE_ID: self._sensor_source_id}
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
|
|
@ -394,13 +394,12 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
state_attr = {}
|
||||
|
||||
if self.state == STATE_ALARM_PENDING or self.state == STATE_ALARM_ARMING:
|
||||
state_attr[ATTR_PREVIOUS_STATE] = self._previous_state
|
||||
state_attr[ATTR_NEXT_STATE] = self._state
|
||||
|
||||
return state_attr
|
||||
return {
|
||||
ATTR_PREVIOUS_STATE: self._previous_state,
|
||||
ATTR_NEXT_STATE: self._state,
|
||||
}
|
||||
return {}
|
||||
|
||||
@callback
|
||||
def async_scheduled_update(self, now):
|
||||
|
|
|
@ -415,13 +415,12 @@ class ManualMQTTAlarm(alarm.AlarmControlPanelEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
state_attr = {}
|
||||
|
||||
if self.state == STATE_ALARM_PENDING:
|
||||
state_attr[ATTR_PRE_PENDING_STATE] = self._previous_state
|
||||
state_attr[ATTR_POST_PENDING_STATE] = self._state
|
||||
|
||||
return state_attr
|
||||
return {
|
||||
ATTR_PRE_PENDING_STATE: self._previous_state,
|
||||
ATTR_POST_PENDING_STATE: self._state,
|
||||
}
|
||||
return {}
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to MQTT events."""
|
||||
|
|
|
@ -286,12 +286,10 @@ class MaxCubeClimate(ClimateEntity):
|
|||
"""Return the optional state attributes."""
|
||||
cube = self._cubehandle.cube
|
||||
device = cube.device_by_rf(self._rf_address)
|
||||
attributes = {}
|
||||
|
||||
if cube.is_thermostat(device):
|
||||
attributes[ATTR_VALVE_POSITION] = device.valve_position
|
||||
|
||||
return attributes
|
||||
return {ATTR_VALVE_POSITION: device.valve_position}
|
||||
return {}
|
||||
|
||||
def update(self):
|
||||
"""Get latest data from MAX! Cube."""
|
||||
|
|
|
@ -228,12 +228,11 @@ class MinMaxSensor(Entity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the sensor."""
|
||||
state_attr = {
|
||||
return {
|
||||
attr: getattr(self, attr)
|
||||
for attr in ATTR_TO_PROPERTY
|
||||
if getattr(self, attr) is not None
|
||||
}
|
||||
return state_attr
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
|
|
@ -197,10 +197,9 @@ class DimmableRflinkLight(SwitchableRflinkDevice, LightEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the device state attributes."""
|
||||
attr = {}
|
||||
if self._brightness is not None:
|
||||
attr[ATTR_BRIGHTNESS] = self._brightness
|
||||
return attr
|
||||
return {ATTR_BRIGHTNESS: self._brightness}
|
||||
return {}
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
|
@ -260,10 +259,9 @@ class HybridRflinkLight(SwitchableRflinkDevice, LightEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the device state attributes."""
|
||||
attr = {}
|
||||
if self._brightness is not None:
|
||||
attr[ATTR_BRIGHTNESS] = self._brightness
|
||||
return attr
|
||||
return {ATTR_BRIGHTNESS: self._brightness}
|
||||
return {}
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
|
|
|
@ -88,8 +88,8 @@ class SesameDevice(LockEntity):
|
|||
@property
|
||||
def device_state_attributes(self) -> dict:
|
||||
"""Return the state attributes."""
|
||||
attributes = {}
|
||||
attributes[ATTR_DEVICE_ID] = self._device_id
|
||||
attributes[ATTR_SERIAL_NO] = self._serial
|
||||
attributes[ATTR_BATTERY_LEVEL] = self._battery
|
||||
return attributes
|
||||
return {
|
||||
ATTR_DEVICE_ID: self._device_id,
|
||||
ATTR_SERIAL_NO: self._serial,
|
||||
ATTR_BATTERY_LEVEL: self._battery,
|
||||
}
|
||||
|
|
|
@ -172,7 +172,6 @@ class SighthoundEntity(ImageProcessingEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the attributes."""
|
||||
attr = {}
|
||||
if self._last_detection:
|
||||
attr["last_person"] = self._last_detection
|
||||
return attr
|
||||
return {"last_person": self._last_detection}
|
||||
return {}
|
||||
|
|
|
@ -262,14 +262,13 @@ class TodoistProjectDevice(CalendarEventDevice):
|
|||
# No tasks, we don't REALLY need to show anything.
|
||||
return None
|
||||
|
||||
attributes = {}
|
||||
attributes[DUE_TODAY] = self.data.event[DUE_TODAY]
|
||||
attributes[OVERDUE] = self.data.event[OVERDUE]
|
||||
attributes[ALL_TASKS] = self._cal_data[ALL_TASKS]
|
||||
attributes[PRIORITY] = self.data.event[PRIORITY]
|
||||
attributes[LABELS] = self.data.event[LABELS]
|
||||
|
||||
return attributes
|
||||
return {
|
||||
DUE_TODAY: self.data.event[DUE_TODAY],
|
||||
OVERDUE: self.data.event[OVERDUE],
|
||||
ALL_TASKS: self._cal_data[ALL_TASKS],
|
||||
PRIORITY: self.data.event[PRIORITY],
|
||||
LABELS: self.data.event[LABELS],
|
||||
}
|
||||
|
||||
|
||||
class TodoistProjectData:
|
||||
|
|
|
@ -233,9 +233,7 @@ class UniFiClientTracker(UniFiClient, ScannerEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the client state attributes."""
|
||||
attributes = {}
|
||||
|
||||
attributes["is_wired"] = self.is_wired
|
||||
attributes = {"is_wired": self.is_wired}
|
||||
|
||||
if self.is_connected:
|
||||
for variable in CLIENT_CONNECTED_ATTRIBUTES:
|
||||
|
|
|
@ -74,13 +74,14 @@ class VeSyncSwitchHA(VeSyncBaseSwitch, SwitchEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the device."""
|
||||
attr = {}
|
||||
if hasattr(self.smartplug, "weekly_energy_total"):
|
||||
attr["voltage"] = self.smartplug.voltage
|
||||
attr["weekly_energy_total"] = self.smartplug.weekly_energy_total
|
||||
attr["monthly_energy_total"] = self.smartplug.monthly_energy_total
|
||||
attr["yearly_energy_total"] = self.smartplug.yearly_energy_total
|
||||
return attr
|
||||
return {
|
||||
"voltage": self.smartplug.voltage,
|
||||
"weekly_energy_total": self.smartplug.weekly_energy_total,
|
||||
"monthly_energy_total": self.smartplug.monthly_energy_total,
|
||||
"yearly_energy_total": self.smartplug.yearly_energy_total,
|
||||
}
|
||||
return {}
|
||||
|
||||
@property
|
||||
def current_power_w(self):
|
||||
|
|
|
@ -320,10 +320,9 @@ class LgWebOSMediaPlayerEntity(MediaPlayerEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return device specific state attributes."""
|
||||
attributes = {}
|
||||
if self._client.sound_output is not None and self.state != STATE_OFF:
|
||||
attributes[ATTR_SOUND_OUTPUT] = self._client.sound_output
|
||||
return attributes
|
||||
return {ATTR_SOUND_OUTPUT: self._client.sound_output}
|
||||
return {}
|
||||
|
||||
@cmd
|
||||
async def async_turn_off(self):
|
||||
|
|
|
@ -106,9 +106,7 @@ class XboxSensor(Entity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
attributes = {}
|
||||
attributes["gamerscore"] = self._gamerscore
|
||||
attributes["tier"] = self._tier
|
||||
attributes = {"gamerscore": self._gamerscore, "tier": self._tier}
|
||||
|
||||
for device in self._presence:
|
||||
for title in device["titles"]:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue