Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions homeassistant/components/deconz/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,7 @@ async def async_turn_off(self, **kwargs):
@property
def device_state_attributes(self):
"""Return the device state attributes."""
attributes = {}
attributes["is_deconz_group"] = self._device.type == "LightGroup"

return attributes
return {"is_deconz_group": self._device.type == "LightGroup"}


class DeconzLight(DeconzBaseLight):
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/denonavr/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,13 @@ def media_episode(self):
@property
def device_state_attributes(self):
"""Return device specific state attributes."""
attributes = {}
if (
self._sound_mode_raw is not None
and self._sound_mode_support
and self._power == "ON"
):
attributes[ATTR_SOUND_MODE_RAW] = self._sound_mode_raw
return attributes
return {ATTR_SOUND_MODE_RAW: self._sound_mode_raw}
return {}

def media_play_pause(self):
"""Play or pause the media player."""
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/derivative/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ def should_poll(self):
@property
def device_state_attributes(self):
"""Return the state attributes of the sensor."""
state_attr = {ATTR_SOURCE_ID: self._sensor_source_id}
return state_attr
return {ATTR_SOURCE_ID: self._sensor_source_id}

@property
def icon(self):
Expand Down
14 changes: 7 additions & 7 deletions homeassistant/components/directv/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ async def async_update(self):
@property
def device_state_attributes(self):
"""Return device specific state attributes."""
attributes = {}
if not self._is_standby:
attributes[ATTR_MEDIA_CURRENTLY_RECORDING] = self.media_currently_recording
attributes[ATTR_MEDIA_RATING] = self.media_rating
attributes[ATTR_MEDIA_RECORDED] = self.media_recorded
attributes[ATTR_MEDIA_START_TIME] = self.media_start_time

return attributes
return {
ATTR_MEDIA_CURRENTLY_RECORDING: self.media_currently_recording,
ATTR_MEDIA_RATING: self.media_rating,
ATTR_MEDIA_RECORDED: self.media_recorded,
ATTR_MEDIA_START_TIME: self.media_start_time,
}
return {}

@property
def name(self):
Expand Down
10 changes: 5 additions & 5 deletions homeassistant/components/eight_sleep/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ async def async_update(self):
@property
def device_state_attributes(self):
"""Return device state attributes."""
state_attr = {ATTR_TARGET_HEAT: self._usrobj.target_heating_level}
state_attr[ATTR_ACTIVE_HEAT] = self._usrobj.now_heating
state_attr[ATTR_DURATION_HEAT] = self._usrobj.heating_remaining

return state_attr
return {
ATTR_TARGET_HEAT: self._usrobj.target_heating_level,
ATTR_ACTIVE_HEAT: self._usrobj.now_heating,
ATTR_DURATION_HEAT: self._usrobj.heating_remaining,
}


class EightUserSensor(EightSleepUserEntity):
Expand Down
22 changes: 9 additions & 13 deletions homeassistant/components/enigma2/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,13 @@ def device_state_attributes(self):
currservice_begin: is in the format '21:00'.
currservice_end: is in the format '21:00'.
"""
attributes = {}
if not self.e2_box.in_standby:
attributes[ATTR_MEDIA_CURRENTLY_RECORDING] = self.e2_box.status_info[
"isRecording"
]
attributes[ATTR_MEDIA_DESCRIPTION] = self.e2_box.status_info[
if self.e2_box.in_standby:
return {}
return {
ATTR_MEDIA_CURRENTLY_RECORDING: self.e2_box.status_info["isRecording"],
ATTR_MEDIA_DESCRIPTION: self.e2_box.status_info[
"currservice_fulldescription"
]
attributes[ATTR_MEDIA_START_TIME] = self.e2_box.status_info[
"currservice_begin"
]
attributes[ATTR_MEDIA_END_TIME] = self.e2_box.status_info["currservice_end"]

return attributes
],
ATTR_MEDIA_START_TIME: self.e2_box.status_info["currservice_begin"],
ATTR_MEDIA_END_TIME: self.e2_box.status_info["currservice_end"],
}
5 changes: 2 additions & 3 deletions homeassistant/components/epson/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ async def async_media_previous_track(self):
@property
def device_state_attributes(self):
"""Return device specific state attributes."""
attributes = {}
if self._cmode is not None:
attributes[ATTR_CMODE] = self._cmode
return attributes
return {ATTR_CMODE: self._cmode}
return {}
3 changes: 1 addition & 2 deletions homeassistant/components/filter/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,7 @@ def should_poll(self):
@property
def device_state_attributes(self):
"""Return the state attributes of the sensor."""
state_attr = {ATTR_ENTITY_ID: self._entity}
return state_attr
return {ATTR_ENTITY_ID: self._entity}


class FilterState:
Expand Down
11 changes: 6 additions & 5 deletions homeassistant/components/flo/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ def is_on(self):
@property
def device_state_attributes(self):
"""Return the state attributes."""
attr = {}
if self._device.has_alerts:
attr["info"] = self._device.pending_info_alerts_count
attr["warning"] = self._device.pending_warning_alerts_count
attr["critical"] = self._device.pending_critical_alerts_count
return attr
return {
"info": self._device.pending_info_alerts_count,
"warning": self._device.pending_warning_alerts_count,
"critical": self._device.pending_critical_alerts_count,
}
return {}

@property
def device_class(self):
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/garmin_connect/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,13 @@ def unit_of_measurement(self):
@property
def device_state_attributes(self):
"""Return attributes for sensor."""
attributes = {}
if self._data.data:
attributes = {
return {
"source": self._data.data["source"],
"last_synced": self._data.data["lastSyncTimestampGMT"],
ATTR_ATTRIBUTION: ATTRIBUTION,
}
return attributes
return {}

@property
def device_info(self) -> Dict[str, Any]:
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/geo_json_events/geo_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ def unit_of_measurement(self):
@property
def device_state_attributes(self):
"""Return the device state attributes."""
attributes = {}
if self._external_id:
attributes[ATTR_EXTERNAL_ID] = self._external_id
return attributes
return {ATTR_EXTERNAL_ID: self._external_id}
return {}
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@ async def set_alarm_state(self, state, code=None):
@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 {}
13 changes: 4 additions & 9 deletions homeassistant/components/homekit_controller/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,13 @@ async def set_door_state(self, state):
@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):
Expand Down Expand Up @@ -249,12 +247,9 @@ async def async_set_cover_tilt_position(self, **kwargs):
@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 {}
5 changes: 2 additions & 3 deletions homeassistant/components/hue/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ async def async_turn_off(self, **kwargs):
@property
def device_state_attributes(self):
"""Return the device state attributes."""
attributes = {}
if self.is_group:
attributes[ATTR_IS_HUE_GROUP] = self.is_group
return attributes
return {ATTR_IS_HUE_GROUP: self.is_group}
return {}
3 changes: 1 addition & 2 deletions homeassistant/components/integration/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ def should_poll(self):
@property
def device_state_attributes(self):
"""Return the state attributes of the sensor."""
state_attr = {ATTR_SOURCE_ID: self._sensor_source_id}
return state_attr
return {ATTR_SOURCE_ID: self._sensor_source_id}

@property
def icon(self):
Expand Down
11 changes: 5 additions & 6 deletions homeassistant/components/manual/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,12 @@ def _validate_code(self, code, state):
@property
def device_state_attributes(self):
"""Return the state attributes."""
state_attr = {}

if self.state == STATE_ALARM_PENDING or self.state == STATE_ALARM_ARMING:
state_attr[ATTR_PREVIOUS_STATE] = self._previous_state
state_attr[ATTR_NEXT_STATE] = self._state

return state_attr
return {
ATTR_PREVIOUS_STATE: self._previous_state,
ATTR_NEXT_STATE: self._state,
}
return {}

@callback
def async_scheduled_update(self, now):
Expand Down
11 changes: 5 additions & 6 deletions homeassistant/components/manual_mqtt/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,12 @@ def _validate_code(self, code, state):
@property
def device_state_attributes(self):
"""Return the state attributes."""
state_attr = {}

if self.state == STATE_ALARM_PENDING:
state_attr[ATTR_PRE_PENDING_STATE] = self._previous_state
state_attr[ATTR_POST_PENDING_STATE] = self._state

return state_attr
return {
ATTR_PRE_PENDING_STATE: self._previous_state,
ATTR_POST_PENDING_STATE: self._state,
}
return {}

async def async_added_to_hass(self):
"""Subscribe to MQTT events."""
Expand Down
6 changes: 2 additions & 4 deletions homeassistant/components/maxcube/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,10 @@ def device_state_attributes(self):
"""Return the optional state attributes."""
cube = self._cubehandle.cube
device = cube.device_by_rf(self._rf_address)
attributes = {}

if cube.is_thermostat(device):
attributes[ATTR_VALVE_POSITION] = device.valve_position

return attributes
return {ATTR_VALVE_POSITION: device.valve_position}
return {}

def update(self):
"""Get latest data from MAX! Cube."""
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/min_max/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,11 @@ def should_poll(self):
@property
def device_state_attributes(self):
"""Return the state attributes of the sensor."""
state_attr = {
return {
attr: getattr(self, attr)
for attr in ATTR_TO_PROPERTY
if getattr(self, attr) is not None
}
return state_attr

@property
def icon(self):
Expand Down
10 changes: 4 additions & 6 deletions homeassistant/components/rflink/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,9 @@ def brightness(self):
@property
def device_state_attributes(self):
"""Return the device state attributes."""
attr = {}
if self._brightness is not None:
attr[ATTR_BRIGHTNESS] = self._brightness
return attr
return {ATTR_BRIGHTNESS: self._brightness}
return {}

@property
def supported_features(self):
Expand Down Expand Up @@ -260,10 +259,9 @@ def brightness(self):
@property
def device_state_attributes(self):
"""Return the device state attributes."""
attr = {}
if self._brightness is not None:
attr[ATTR_BRIGHTNESS] = self._brightness
return attr
return {ATTR_BRIGHTNESS: self._brightness}
return {}

@property
def supported_features(self):
Expand Down
10 changes: 5 additions & 5 deletions homeassistant/components/sesame/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def update(self) -> None:
@property
def device_state_attributes(self) -> dict:
"""Return the state attributes."""
attributes = {}
attributes[ATTR_DEVICE_ID] = self._device_id
attributes[ATTR_SERIAL_NO] = self._serial
attributes[ATTR_BATTERY_LEVEL] = self._battery
return attributes
return {
ATTR_DEVICE_ID: self._device_id,
ATTR_SERIAL_NO: self._serial,
ATTR_BATTERY_LEVEL: self._battery,
}
5 changes: 2 additions & 3 deletions homeassistant/components/sighthound/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ def unit_of_measurement(self):
@property
def device_state_attributes(self):
"""Return the attributes."""
attr = {}
if self._last_detection:
attr["last_person"] = self._last_detection
return attr
return {"last_person": self._last_detection}
return {}
15 changes: 7 additions & 8 deletions homeassistant/components/todoist/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,13 @@ def device_state_attributes(self):
# No tasks, we don't REALLY need to show anything.
return None

attributes = {}
attributes[DUE_TODAY] = self.data.event[DUE_TODAY]
attributes[OVERDUE] = self.data.event[OVERDUE]
attributes[ALL_TASKS] = self._cal_data[ALL_TASKS]
attributes[PRIORITY] = self.data.event[PRIORITY]
attributes[LABELS] = self.data.event[LABELS]

return attributes
return {
DUE_TODAY: self.data.event[DUE_TODAY],
OVERDUE: self.data.event[OVERDUE],
ALL_TASKS: self._cal_data[ALL_TASKS],
PRIORITY: self.data.event[PRIORITY],
LABELS: self.data.event[LABELS],
}


class TodoistProjectData:
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/unifi/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,7 @@ def unique_id(self) -> str:
@property
def device_state_attributes(self):
"""Return the client state attributes."""
attributes = {}

attributes["is_wired"] = self.is_wired
attributes = {"is_wired": self.is_wired}

if self.is_connected:
for variable in CLIENT_CONNECTED_ATTRIBUTES:
Expand Down
Loading