Return attribute dict directly without temporary variable (#41206)
parent
cf5c99d2a9
commit
038c05d0ee
|
@ -175,12 +175,11 @@ class AlarmControlPanelEntity(Entity):
|
|||
@property
|
||||
def state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
state_attr = {
|
||||
return {
|
||||
ATTR_CODE_FORMAT: self.code_format,
|
||||
ATTR_CHANGED_BY: self.changed_by,
|
||||
ATTR_CODE_ARM_REQUIRED: self.code_arm_required,
|
||||
}
|
||||
return state_attr
|
||||
|
||||
|
||||
class AlarmControlPanel(AlarmControlPanelEntity):
|
||||
|
|
|
@ -120,8 +120,7 @@ class AlarmDecoderBinarySensor(BinarySensorEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
attr = {}
|
||||
attr[CONF_ZONE_NUMBER] = self._zone_number
|
||||
attr = {CONF_ZONE_NUMBER: self._zone_number}
|
||||
if self._rfid and self._rfstate is not None:
|
||||
attr[ATTR_RF_BIT0] = bool(self._rfstate & 0x01)
|
||||
attr[ATTR_RF_LOW_BAT] = bool(self._rfstate & 0x02)
|
||||
|
|
|
@ -175,7 +175,7 @@ class BOMCurrentSensor(Entity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the device."""
|
||||
attr = {
|
||||
return {
|
||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
||||
ATTR_LAST_UPDATE: self.bom_data.last_updated,
|
||||
ATTR_SENSOR_ID: self._condition,
|
||||
|
@ -184,8 +184,6 @@ class BOMCurrentSensor(Entity):
|
|||
ATTR_ZONE_ID: self.bom_data.latest_data["history_product"],
|
||||
}
|
||||
|
||||
return attr
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the units of measurement."""
|
||||
|
|
|
@ -86,9 +86,7 @@ class ECCamera(Camera):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the device."""
|
||||
attr = {ATTR_ATTRIBUTION: CONF_ATTRIBUTION, ATTR_UPDATED: self.timestamp}
|
||||
|
||||
return attr
|
||||
return {ATTR_ATTRIBUTION: CONF_ATTRIBUTION, ATTR_UPDATED: self.timestamp}
|
||||
|
||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||
def update(self):
|
||||
|
|
|
@ -78,12 +78,11 @@ class Filesize(Entity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return other details about the sensor state."""
|
||||
attr = {
|
||||
return {
|
||||
"path": self._path,
|
||||
"last_updated": self._last_updated,
|
||||
"bytes": self._size,
|
||||
}
|
||||
return attr
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
|
|
|
@ -94,14 +94,13 @@ class Folder(Entity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return other details about the sensor state."""
|
||||
attr = {
|
||||
return {
|
||||
"path": self._folder_path,
|
||||
"filter": self._filter_term,
|
||||
"number_of_files": self._number_of_files,
|
||||
"bytes": self._size,
|
||||
"file_list": self._file_list,
|
||||
}
|
||||
return attr
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
|
|
|
@ -98,7 +98,7 @@ class FritzboxMonitorSensor(Entity):
|
|||
# Don't return attributes if FritzBox is unreachable
|
||||
if self._state == STATE_UNAVAILABLE:
|
||||
return {}
|
||||
attr = {
|
||||
return {
|
||||
ATTR_IS_LINKED: self._is_linked,
|
||||
ATTR_IS_CONNECTED: self._is_connected,
|
||||
ATTR_EXTERNAL_IP: self._external_ip,
|
||||
|
@ -110,7 +110,6 @@ class FritzboxMonitorSensor(Entity):
|
|||
ATTR_MAX_BYTE_RATE_UP: self._max_byte_rate_up,
|
||||
ATTR_MAX_BYTE_RATE_DOWN: self._max_byte_rate_down,
|
||||
}
|
||||
return attr
|
||||
|
||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||
def update(self):
|
||||
|
|
|
@ -255,8 +255,7 @@ class HikvisionBinarySensor(BinarySensorEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
attr = {}
|
||||
attr[ATTR_LAST_TRIP_TIME] = self._sensor_last_update()
|
||||
attr = {ATTR_LAST_TRIP_TIME: self._sensor_last_update()}
|
||||
|
||||
if self._delay != 0:
|
||||
attr[ATTR_DELAY] = self._delay
|
||||
|
|
|
@ -233,8 +233,7 @@ class HMHub(Entity):
|
|||
@property
|
||||
def state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
attr = self._variables.copy()
|
||||
return attr
|
||||
return self._variables.copy()
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
|
|
@ -173,9 +173,7 @@ class ImageProcessingFaceEntity(ImageProcessingEntity):
|
|||
@property
|
||||
def state_attributes(self):
|
||||
"""Return device specific state attributes."""
|
||||
attr = {ATTR_FACES: self.faces, ATTR_TOTAL_FACES: self.total_faces}
|
||||
|
||||
return attr
|
||||
return {ATTR_FACES: self.faces, ATTR_TOTAL_FACES: self.total_faces}
|
||||
|
||||
def process_faces(self, faces, total):
|
||||
"""Send event with detected faces and store data."""
|
||||
|
|
|
@ -72,8 +72,7 @@ class IotaDevice(Entity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the device."""
|
||||
attr = {CONF_WALLET_NAME: self._name}
|
||||
return attr
|
||||
return {CONF_WALLET_NAME: self._name}
|
||||
|
||||
@property
|
||||
def api(self):
|
||||
|
|
|
@ -51,6 +51,4 @@ class LutronOccupancySensor(LutronDevice, BinarySensorEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
attr = {}
|
||||
attr["lutron_integration_id"] = self._lutron_device.id
|
||||
return attr
|
||||
return {"lutron_integration_id": self._lutron_device.id}
|
||||
|
|
|
@ -66,6 +66,4 @@ class LutronCover(LutronDevice, CoverEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
attr = {}
|
||||
attr["Lutron Integration ID"] = self._lutron_device.id
|
||||
return attr
|
||||
return {"Lutron Integration ID": self._lutron_device.id}
|
||||
|
|
|
@ -71,8 +71,7 @@ class LutronLight(LutronDevice, LightEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
attr = {"lutron_integration_id": self._lutron_device.id}
|
||||
return attr
|
||||
return {"lutron_integration_id": self._lutron_device.id}
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
|
|
|
@ -48,9 +48,7 @@ class LutronSwitch(LutronDevice, SwitchEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
attr = {}
|
||||
attr["lutron_integration_id"] = self._lutron_device.id
|
||||
return attr
|
||||
return {"lutron_integration_id": self._lutron_device.id}
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
|
@ -83,12 +81,11 @@ class LutronLed(LutronDevice, SwitchEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
attr = {
|
||||
return {
|
||||
"keypad": self._keypad_name,
|
||||
"scene": self._scene_name,
|
||||
"led": self._lutron_device.name,
|
||||
}
|
||||
return attr
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
|
|
|
@ -109,7 +109,7 @@ class MfiSwitch(SwitchEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes for the device."""
|
||||
attr = {}
|
||||
attr["volts"] = round(self._port.data.get("v_rms", 0), 1)
|
||||
attr["amps"] = round(self._port.data.get("i_rms", 0), 1)
|
||||
return attr
|
||||
return {
|
||||
"volts": round(self._port.data.get("v_rms", 0), 1),
|
||||
"amps": round(self._port.data.get("i_rms", 0), 1),
|
||||
}
|
||||
|
|
|
@ -184,8 +184,7 @@ class MiFloraSensor(Entity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the device."""
|
||||
attr = {ATTR_LAST_SUCCESSFUL_UPDATE: self.last_successful_update}
|
||||
return attr
|
||||
return {ATTR_LAST_SUCCESSFUL_UPDATE: self.last_successful_update}
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
|
|
|
@ -104,9 +104,7 @@ class ImageProcessingAlprEntity(ImageProcessingEntity):
|
|||
@property
|
||||
def state_attributes(self):
|
||||
"""Return device specific state attributes."""
|
||||
attr = {ATTR_PLATES: self.plates, ATTR_VEHICLES: self.vehicles}
|
||||
|
||||
return attr
|
||||
return {ATTR_PLATES: self.plates, ATTR_VEHICLES: self.vehicles}
|
||||
|
||||
def process_plates(self, plates, vehicles):
|
||||
"""Send event with new plates and store data."""
|
||||
|
|
|
@ -597,7 +597,7 @@ class PlexMediaPlayer(MediaPlayerEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the scene state attributes."""
|
||||
attr = {
|
||||
return {
|
||||
"media_content_rating": self._media_content_rating,
|
||||
"session_username": self.username,
|
||||
"media_library_name": self._app_name,
|
||||
|
@ -605,8 +605,6 @@ class PlexMediaPlayer(MediaPlayerEntity):
|
|||
"player_source": self.player_source,
|
||||
}
|
||||
|
||||
return attr
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return a device description for device registry."""
|
||||
|
|
|
@ -142,7 +142,7 @@ class SimulatedSensor(Entity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return other details about the sensor state."""
|
||||
attr = {
|
||||
return {
|
||||
"amplitude": self._amp,
|
||||
"mean": self._mean,
|
||||
"period": self._period,
|
||||
|
@ -151,4 +151,3 @@ class SimulatedSensor(Entity):
|
|||
"seed": self._seed,
|
||||
"relative_to_epoch": self._relative_to_epoch,
|
||||
}
|
||||
return attr
|
||||
|
|
|
@ -103,7 +103,7 @@ class SwissPublicTransportSensor(Entity):
|
|||
self._opendata.connections[0]["departure"]
|
||||
) - dt_util.as_local(dt_util.utcnow())
|
||||
|
||||
attr = {
|
||||
return {
|
||||
ATTR_TRAIN_NUMBER: self._opendata.connections[0]["number"],
|
||||
ATTR_PLATFORM: self._opendata.connections[0]["platform"],
|
||||
ATTR_TRANSFERS: self._opendata.connections[0]["transfers"],
|
||||
|
@ -116,7 +116,6 @@ class SwissPublicTransportSensor(Entity):
|
|||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
||||
ATTR_DELAY: self._opendata.connections[0]["delay"],
|
||||
}
|
||||
return attr
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
|
|
@ -67,7 +67,4 @@ class SynoDSMStorageBinarySensor(SynologyDSMDeviceEntity, BinarySensorEntity):
|
|||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return the state."""
|
||||
attr = getattr(self._api.storage, self.entity_type)(self._device_id)
|
||||
if attr is None:
|
||||
return None
|
||||
return attr
|
||||
return getattr(self._api.storage, self.entity_type)(self._device_id)
|
||||
|
|
|
@ -31,8 +31,7 @@ class TradfriCover(TradfriBaseDevice, CoverEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
attr = {ATTR_MODEL: self._device.device_info.model_number}
|
||||
return attr
|
||||
return {ATTR_MODEL: self._device.device_info.model_number}
|
||||
|
||||
@property
|
||||
def current_cover_position(self):
|
||||
|
|
Loading…
Reference in New Issue