Return empty dictionary at first for attributes (#41348)

This commit is contained in:
springstan 2020-10-06 18:08:53 +02:00 committed by GitHub
parent 4d12fcc218
commit 61d9067a49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 75 additions and 77 deletions

View File

@ -126,14 +126,14 @@ class DIRECTVMediaPlayer(DIRECTVEntity, MediaPlayerEntity):
@property
def device_state_attributes(self):
"""Return device specific state attributes."""
if not self._is_standby:
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 {}
if self._is_standby:
return {}
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,
}
@property
def name(self):

View File

@ -235,6 +235,6 @@ class EpsonProjector(MediaPlayerEntity):
@property
def device_state_attributes(self):
"""Return device specific state attributes."""
if self._cmode is not None:
return {ATTR_CMODE: self._cmode}
return {}
if self._cmode is None:
return {}
return {ATTR_CMODE: self._cmode}

View File

@ -36,13 +36,13 @@ class FloPendingAlertsBinarySensor(FloEntity, BinarySensorEntity):
@property
def device_state_attributes(self):
"""Return the state attributes."""
if self._device.has_alerts:
return {
"info": self._device.pending_info_alerts_count,
"warning": self._device.pending_warning_alerts_count,
"critical": self._device.pending_critical_alerts_count,
}
return {}
if not self._device.has_alerts:
return {}
return {
"info": self._device.pending_info_alerts_count,
"warning": self._device.pending_warning_alerts_count,
"critical": self._device.pending_critical_alerts_count,
}
@property
def device_class(self):

View File

@ -121,13 +121,13 @@ class GarminConnectSensor(Entity):
@property
def device_state_attributes(self):
"""Return attributes for sensor."""
if self._data.data:
return {
"source": self._data.data["source"],
"last_synced": self._data.data["lastSyncTimestampGMT"],
ATTR_ATTRIBUTION: ATTRIBUTION,
}
return {}
if not self._data.data:
return {}
return {
"source": self._data.data["source"],
"last_synced": self._data.data["lastSyncTimestampGMT"],
ATTR_ATTRIBUTION: ATTRIBUTION,
}
@property
def device_info(self) -> Dict[str, Any]:

View File

@ -203,6 +203,6 @@ class GeoJsonLocationEvent(GeolocationEvent):
@property
def device_state_attributes(self):
"""Return the device state attributes."""
if self._external_id:
return {ATTR_EXTERNAL_ID: self._external_id}
return {}
if not self._external_id:
return {}
return {ATTR_EXTERNAL_ID: self._external_id}

View File

@ -112,6 +112,6 @@ class HomeKitAlarmControlPanelEntity(HomeKitEntity, AlarmControlPanelEntity):
"""Return the optional state attributes."""
battery_level = self.service.value(CharacteristicsTypes.BATTERY_LEVEL)
if battery_level:
return {ATTR_BATTERY_LEVEL: battery_level}
return {}
if not battery_level:
return {}
return {ATTR_BATTERY_LEVEL: battery_level}

View File

@ -120,10 +120,9 @@ class HomeKitGarageDoorCover(HomeKitEntity, CoverEntity):
obstruction_detected = self.service.value(
CharacteristicsTypes.OBSTRUCTION_DETECTED
)
if obstruction_detected:
return {"obstruction-detected": obstruction_detected}
return {}
if not obstruction_detected:
return {}
return {"obstruction-detected": obstruction_detected}
class HomeKitWindowCover(HomeKitEntity, CoverEntity):
@ -250,6 +249,6 @@ class HomeKitWindowCover(HomeKitEntity, CoverEntity):
obstruction_detected = self.service.value(
CharacteristicsTypes.OBSTRUCTION_DETECTED
)
if obstruction_detected:
return {"obstruction-detected": obstruction_detected}
return {}
if not obstruction_detected:
return {}
return {"obstruction-detected": obstruction_detected}

View File

@ -458,6 +458,6 @@ class HueLight(CoordinatorEntity, LightEntity):
@property
def device_state_attributes(self):
"""Return the device state attributes."""
if self.is_group:
return {ATTR_IS_HUE_GROUP: self.is_group}
return {}
if not self.is_group:
return {}
return {ATTR_IS_HUE_GROUP: self.is_group}

View File

@ -113,10 +113,9 @@ class JewishCalendarSensor(Entity):
@property
def device_state_attributes(self):
"""Return the state attributes."""
if self._type == "holiday":
return self._holiday_attrs
return {}
if self._type != "holiday":
return {}
return self._holiday_attrs
def get_state(self, daytime_date, after_shkia_date, after_tzais_date):
"""For a given type of sensor, return the state."""

View File

@ -415,12 +415,12 @@ class ManualMQTTAlarm(alarm.AlarmControlPanelEntity):
@property
def device_state_attributes(self):
"""Return the state attributes."""
if self.state == STATE_ALARM_PENDING:
return {
ATTR_PRE_PENDING_STATE: self._previous_state,
ATTR_POST_PENDING_STATE: self._state,
}
return {}
if self.state != STATE_ALARM_PENDING:
return {}
return {
ATTR_PRE_PENDING_STATE: self._previous_state,
ATTR_POST_PENDING_STATE: self._state,
}
async def async_added_to_hass(self):
"""Subscribe to MQTT events."""

View File

@ -287,9 +287,9 @@ class MaxCubeClimate(ClimateEntity):
cube = self._cubehandle.cube
device = cube.device_by_rf(self._rf_address)
if cube.is_thermostat(device):
return {ATTR_VALVE_POSITION: device.valve_position}
return {}
if not cube.is_thermostat(device):
return {}
return {ATTR_VALVE_POSITION: device.valve_position}
def update(self):
"""Get latest data from MAX! Cube."""

View File

@ -61,6 +61,6 @@ class OPNSenseDeviceScanner(DeviceScanner):
if device not in self.last_results:
return None
mfg = self.last_results[device].get("manufacturer")
if mfg:
return {"manufacturer": mfg}
return {}
if not mfg:
return {}
return {"manufacturer": mfg}

View File

@ -197,9 +197,9 @@ class DimmableRflinkLight(SwitchableRflinkDevice, LightEntity):
@property
def device_state_attributes(self):
"""Return the device state attributes."""
if self._brightness is not None:
return {ATTR_BRIGHTNESS: self._brightness}
return {}
if self._brightness is None:
return {}
return {ATTR_BRIGHTNESS: self._brightness}
@property
def supported_features(self):
@ -259,9 +259,9 @@ class HybridRflinkLight(SwitchableRflinkDevice, LightEntity):
@property
def device_state_attributes(self):
"""Return the device state attributes."""
if self._brightness is not None:
return {ATTR_BRIGHTNESS: self._brightness}
return {}
if self._brightness is None:
return {}
return {ATTR_BRIGHTNESS: self._brightness}
@property
def supported_features(self):

View File

@ -172,6 +172,6 @@ class SighthoundEntity(ImageProcessingEntity):
@property
def device_state_attributes(self):
"""Return the attributes."""
if self._last_detection:
return {"last_person": self._last_detection}
return {}
if not self._last_detection:
return {}
return {"last_person": self._last_detection}

View File

@ -74,14 +74,14 @@ class VeSyncSwitchHA(VeSyncBaseSwitch, SwitchEntity):
@property
def device_state_attributes(self):
"""Return the state attributes of the device."""
if hasattr(self.smartplug, "weekly_energy_total"):
return {
"voltage": self.smartplug.voltage,
"weekly_energy_total": self.smartplug.weekly_energy_total,
"monthly_energy_total": self.smartplug.monthly_energy_total,
"yearly_energy_total": self.smartplug.yearly_energy_total,
}
return {}
if not hasattr(self.smartplug, "weekly_energy_total"):
return {}
return {
"voltage": self.smartplug.voltage,
"weekly_energy_total": self.smartplug.weekly_energy_total,
"monthly_energy_total": self.smartplug.monthly_energy_total,
"yearly_energy_total": self.smartplug.yearly_energy_total,
}
@property
def current_power_w(self):

View File

@ -320,9 +320,9 @@ class LgWebOSMediaPlayerEntity(MediaPlayerEntity):
@property
def device_state_attributes(self):
"""Return device specific state attributes."""
if self._client.sound_output is not None and self.state != STATE_OFF:
return {ATTR_SOUND_OUTPUT: self._client.sound_output}
return {}
if self._client.sound_output is None and self.state == STATE_OFF:
return {}
return {ATTR_SOUND_OUTPUT: self._client.sound_output}
@cmd
async def async_turn_off(self):