Return attribute dict directly without temporary variable (#41206)

pull/41266/head
springstan 2020-10-05 12:51:48 +02:00 committed by GitHub
parent cf5c99d2a9
commit 038c05d0ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 27 additions and 60 deletions

View File

@ -175,12 +175,11 @@ class AlarmControlPanelEntity(Entity):
@property @property
def state_attributes(self): def state_attributes(self):
"""Return the state attributes.""" """Return the state attributes."""
state_attr = { return {
ATTR_CODE_FORMAT: self.code_format, ATTR_CODE_FORMAT: self.code_format,
ATTR_CHANGED_BY: self.changed_by, ATTR_CHANGED_BY: self.changed_by,
ATTR_CODE_ARM_REQUIRED: self.code_arm_required, ATTR_CODE_ARM_REQUIRED: self.code_arm_required,
} }
return state_attr
class AlarmControlPanel(AlarmControlPanelEntity): class AlarmControlPanel(AlarmControlPanelEntity):

View File

@ -120,8 +120,7 @@ class AlarmDecoderBinarySensor(BinarySensorEntity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes.""" """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: if self._rfid and self._rfstate is not None:
attr[ATTR_RF_BIT0] = bool(self._rfstate & 0x01) attr[ATTR_RF_BIT0] = bool(self._rfstate & 0x01)
attr[ATTR_RF_LOW_BAT] = bool(self._rfstate & 0x02) attr[ATTR_RF_LOW_BAT] = bool(self._rfstate & 0x02)

View File

@ -175,7 +175,7 @@ class BOMCurrentSensor(Entity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes of the device.""" """Return the state attributes of the device."""
attr = { return {
ATTR_ATTRIBUTION: ATTRIBUTION, ATTR_ATTRIBUTION: ATTRIBUTION,
ATTR_LAST_UPDATE: self.bom_data.last_updated, ATTR_LAST_UPDATE: self.bom_data.last_updated,
ATTR_SENSOR_ID: self._condition, ATTR_SENSOR_ID: self._condition,
@ -184,8 +184,6 @@ class BOMCurrentSensor(Entity):
ATTR_ZONE_ID: self.bom_data.latest_data["history_product"], ATTR_ZONE_ID: self.bom_data.latest_data["history_product"],
} }
return attr
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
"""Return the units of measurement.""" """Return the units of measurement."""

View File

@ -86,9 +86,7 @@ class ECCamera(Camera):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes of the device.""" """Return the state attributes of the device."""
attr = {ATTR_ATTRIBUTION: CONF_ATTRIBUTION, ATTR_UPDATED: self.timestamp} return {ATTR_ATTRIBUTION: CONF_ATTRIBUTION, ATTR_UPDATED: self.timestamp}
return attr
@Throttle(MIN_TIME_BETWEEN_UPDATES) @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self): def update(self):

View File

@ -78,12 +78,11 @@ class Filesize(Entity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return other details about the sensor state.""" """Return other details about the sensor state."""
attr = { return {
"path": self._path, "path": self._path,
"last_updated": self._last_updated, "last_updated": self._last_updated,
"bytes": self._size, "bytes": self._size,
} }
return attr
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):

View File

@ -94,14 +94,13 @@ class Folder(Entity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return other details about the sensor state.""" """Return other details about the sensor state."""
attr = { return {
"path": self._folder_path, "path": self._folder_path,
"filter": self._filter_term, "filter": self._filter_term,
"number_of_files": self._number_of_files, "number_of_files": self._number_of_files,
"bytes": self._size, "bytes": self._size,
"file_list": self._file_list, "file_list": self._file_list,
} }
return attr
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):

View File

@ -98,7 +98,7 @@ class FritzboxMonitorSensor(Entity):
# Don't return attributes if FritzBox is unreachable # Don't return attributes if FritzBox is unreachable
if self._state == STATE_UNAVAILABLE: if self._state == STATE_UNAVAILABLE:
return {} return {}
attr = { return {
ATTR_IS_LINKED: self._is_linked, ATTR_IS_LINKED: self._is_linked,
ATTR_IS_CONNECTED: self._is_connected, ATTR_IS_CONNECTED: self._is_connected,
ATTR_EXTERNAL_IP: self._external_ip, 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_UP: self._max_byte_rate_up,
ATTR_MAX_BYTE_RATE_DOWN: self._max_byte_rate_down, ATTR_MAX_BYTE_RATE_DOWN: self._max_byte_rate_down,
} }
return attr
@Throttle(MIN_TIME_BETWEEN_UPDATES) @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self): def update(self):

View File

@ -255,8 +255,7 @@ class HikvisionBinarySensor(BinarySensorEntity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes.""" """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: if self._delay != 0:
attr[ATTR_DELAY] = self._delay attr[ATTR_DELAY] = self._delay

View File

@ -233,8 +233,7 @@ class HMHub(Entity):
@property @property
def state_attributes(self): def state_attributes(self):
"""Return the state attributes.""" """Return the state attributes."""
attr = self._variables.copy() return self._variables.copy()
return attr
@property @property
def icon(self): def icon(self):

View File

@ -173,9 +173,7 @@ class ImageProcessingFaceEntity(ImageProcessingEntity):
@property @property
def state_attributes(self): def state_attributes(self):
"""Return device specific state attributes.""" """Return device specific state attributes."""
attr = {ATTR_FACES: self.faces, ATTR_TOTAL_FACES: self.total_faces} return {ATTR_FACES: self.faces, ATTR_TOTAL_FACES: self.total_faces}
return attr
def process_faces(self, faces, total): def process_faces(self, faces, total):
"""Send event with detected faces and store data.""" """Send event with detected faces and store data."""

View File

@ -72,8 +72,7 @@ class IotaDevice(Entity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes of the device.""" """Return the state attributes of the device."""
attr = {CONF_WALLET_NAME: self._name} return {CONF_WALLET_NAME: self._name}
return attr
@property @property
def api(self): def api(self):

View File

@ -51,6 +51,4 @@ class LutronOccupancySensor(LutronDevice, BinarySensorEntity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes.""" """Return the state attributes."""
attr = {} return {"lutron_integration_id": self._lutron_device.id}
attr["lutron_integration_id"] = self._lutron_device.id
return attr

View File

@ -66,6 +66,4 @@ class LutronCover(LutronDevice, CoverEntity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes.""" """Return the state attributes."""
attr = {} return {"Lutron Integration ID": self._lutron_device.id}
attr["Lutron Integration ID"] = self._lutron_device.id
return attr

View File

@ -71,8 +71,7 @@ class LutronLight(LutronDevice, LightEntity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes.""" """Return the state attributes."""
attr = {"lutron_integration_id": self._lutron_device.id} return {"lutron_integration_id": self._lutron_device.id}
return attr
@property @property
def is_on(self): def is_on(self):

View File

@ -48,9 +48,7 @@ class LutronSwitch(LutronDevice, SwitchEntity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes.""" """Return the state attributes."""
attr = {} return {"lutron_integration_id": self._lutron_device.id}
attr["lutron_integration_id"] = self._lutron_device.id
return attr
@property @property
def is_on(self): def is_on(self):
@ -83,12 +81,11 @@ class LutronLed(LutronDevice, SwitchEntity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes.""" """Return the state attributes."""
attr = { return {
"keypad": self._keypad_name, "keypad": self._keypad_name,
"scene": self._scene_name, "scene": self._scene_name,
"led": self._lutron_device.name, "led": self._lutron_device.name,
} }
return attr
@property @property
def is_on(self): def is_on(self):

View File

@ -109,7 +109,7 @@ class MfiSwitch(SwitchEntity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes for the device.""" """Return the state attributes for the device."""
attr = {} return {
attr["volts"] = round(self._port.data.get("v_rms", 0), 1) "volts": round(self._port.data.get("v_rms", 0), 1),
attr["amps"] = round(self._port.data.get("i_rms", 0), 1) "amps": round(self._port.data.get("i_rms", 0), 1),
return attr }

View File

@ -184,8 +184,7 @@ class MiFloraSensor(Entity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes of the device.""" """Return the state attributes of the device."""
attr = {ATTR_LAST_SUCCESSFUL_UPDATE: self.last_successful_update} return {ATTR_LAST_SUCCESSFUL_UPDATE: self.last_successful_update}
return attr
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):

View File

@ -104,9 +104,7 @@ class ImageProcessingAlprEntity(ImageProcessingEntity):
@property @property
def state_attributes(self): def state_attributes(self):
"""Return device specific state attributes.""" """Return device specific state attributes."""
attr = {ATTR_PLATES: self.plates, ATTR_VEHICLES: self.vehicles} return {ATTR_PLATES: self.plates, ATTR_VEHICLES: self.vehicles}
return attr
def process_plates(self, plates, vehicles): def process_plates(self, plates, vehicles):
"""Send event with new plates and store data.""" """Send event with new plates and store data."""

View File

@ -597,7 +597,7 @@ class PlexMediaPlayer(MediaPlayerEntity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the scene state attributes.""" """Return the scene state attributes."""
attr = { return {
"media_content_rating": self._media_content_rating, "media_content_rating": self._media_content_rating,
"session_username": self.username, "session_username": self.username,
"media_library_name": self._app_name, "media_library_name": self._app_name,
@ -605,8 +605,6 @@ class PlexMediaPlayer(MediaPlayerEntity):
"player_source": self.player_source, "player_source": self.player_source,
} }
return attr
@property @property
def device_info(self): def device_info(self):
"""Return a device description for device registry.""" """Return a device description for device registry."""

View File

@ -142,7 +142,7 @@ class SimulatedSensor(Entity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return other details about the sensor state.""" """Return other details about the sensor state."""
attr = { return {
"amplitude": self._amp, "amplitude": self._amp,
"mean": self._mean, "mean": self._mean,
"period": self._period, "period": self._period,
@ -151,4 +151,3 @@ class SimulatedSensor(Entity):
"seed": self._seed, "seed": self._seed,
"relative_to_epoch": self._relative_to_epoch, "relative_to_epoch": self._relative_to_epoch,
} }
return attr

View File

@ -103,7 +103,7 @@ class SwissPublicTransportSensor(Entity):
self._opendata.connections[0]["departure"] self._opendata.connections[0]["departure"]
) - dt_util.as_local(dt_util.utcnow()) ) - dt_util.as_local(dt_util.utcnow())
attr = { return {
ATTR_TRAIN_NUMBER: self._opendata.connections[0]["number"], ATTR_TRAIN_NUMBER: self._opendata.connections[0]["number"],
ATTR_PLATFORM: self._opendata.connections[0]["platform"], ATTR_PLATFORM: self._opendata.connections[0]["platform"],
ATTR_TRANSFERS: self._opendata.connections[0]["transfers"], ATTR_TRANSFERS: self._opendata.connections[0]["transfers"],
@ -116,7 +116,6 @@ class SwissPublicTransportSensor(Entity):
ATTR_ATTRIBUTION: ATTRIBUTION, ATTR_ATTRIBUTION: ATTRIBUTION,
ATTR_DELAY: self._opendata.connections[0]["delay"], ATTR_DELAY: self._opendata.connections[0]["delay"],
} }
return attr
@property @property
def icon(self): def icon(self):

View File

@ -67,7 +67,4 @@ class SynoDSMStorageBinarySensor(SynologyDSMDeviceEntity, BinarySensorEntity):
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return the state.""" """Return the state."""
attr = getattr(self._api.storage, self.entity_type)(self._device_id) return getattr(self._api.storage, self.entity_type)(self._device_id)
if attr is None:
return None
return attr

View File

@ -31,8 +31,7 @@ class TradfriCover(TradfriBaseDevice, CoverEntity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes.""" """Return the state attributes."""
attr = {ATTR_MODEL: self._device.device_info.model_number} return {ATTR_MODEL: self._device.device_info.model_number}
return attr
@property @property
def current_cover_position(self): def current_cover_position(self):