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
|
@ -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 {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue