Return attribute dict directly without temporary variable v3 (#41502)

This commit is contained in:
springstan 2020-10-08 21:33:08 +02:00 committed by GitHub
parent f42eca3fcf
commit 916178925e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 9 deletions

View file

@ -508,7 +508,7 @@ class FibaroDevice(Entity):
@property
def device_state_attributes(self):
"""Return the state attributes of the device."""
attr = {}
attr = {"fibaro_id": self.fibaro_device.id}
try:
if "battery" in self.fibaro_device.interfaces:
@ -528,5 +528,4 @@ class FibaroDevice(Entity):
except (ValueError, KeyError):
pass
attr["fibaro_id"] = self.fibaro_device.id
return attr

View file

@ -73,7 +73,12 @@ class HMDevice(Entity):
@property
def device_state_attributes(self):
"""Return device specific state attributes."""
attr = {}
# Static attributes
attr = {
"id": self._hmdevice.ADDRESS,
"interface": self._interface,
}
# Generate a dictionary with attributes
for node, data in HM_ATTRIBUTE_SUPPORT.items():
@ -82,10 +87,6 @@ class HMDevice(Entity):
value = data[1].get(self._data[node], self._data[node])
attr[data[0]] = value
# Static attributes
attr["id"] = self._hmdevice.ADDRESS
attr["interface"] = self._interface
return attr
def update(self):

View file

@ -140,8 +140,7 @@ class LutronCasetaDevice(Entity):
@property
def device_state_attributes(self):
"""Return the state attributes."""
attr = {"device_id": self.device_id, "zone_id": self._device["zone"]}
return attr
return {"device_id": self.device_id, "zone_id": self._device["zone"]}
@property
def should_poll(self):