Return attribute dict directly without temporary variable v2 (#41271)

This commit is contained in:
springstan 2020-10-06 16:55:16 +02:00 committed by GitHub
parent 33e69fe4bf
commit 513f03eb1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 90 additions and 124 deletions

View file

@ -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 {}

View file

@ -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 {}