Return empty dictionary at first for attributes (#41348)
This commit is contained in:
parent
4d12fcc218
commit
61d9067a49
16 changed files with 75 additions and 77 deletions
|
@ -126,14 +126,14 @@ class DIRECTVMediaPlayer(DIRECTVEntity, MediaPlayerEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return device specific state attributes."""
|
||||
if not self._is_standby:
|
||||
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,
|
||||
}
|
||||
return {}
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -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}
|
||||
if self._cmode is None:
|
||||
return {}
|
||||
return {ATTR_CMODE: self._cmode}
|
||||
|
|
|
@ -36,13 +36,13 @@ class FloPendingAlertsBinarySensor(FloEntity, BinarySensorEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
if self._device.has_alerts:
|
||||
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,
|
||||
}
|
||||
return {}
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
|
|
|
@ -121,13 +121,13 @@ class GarminConnectSensor(Entity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return attributes for sensor."""
|
||||
if self._data.data:
|
||||
if not self._data.data:
|
||||
return {}
|
||||
return {
|
||||
"source": self._data.data["source"],
|
||||
"last_synced": self._data.data["lastSyncTimestampGMT"],
|
||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
||||
}
|
||||
return {}
|
||||
|
||||
@property
|
||||
def device_info(self) -> Dict[str, Any]:
|
||||
|
|
|
@ -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}
|
||||
if not self._external_id:
|
||||
return {}
|
||||
return {ATTR_EXTERNAL_ID: self._external_id}
|
||||
|
|
|
@ -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}
|
||||
if not battery_level:
|
||||
return {}
|
||||
return {ATTR_BATTERY_LEVEL: battery_level}
|
||||
|
|
|
@ -120,10 +120,9 @@ class HomeKitGarageDoorCover(HomeKitEntity, CoverEntity):
|
|||
obstruction_detected = self.service.value(
|
||||
CharacteristicsTypes.OBSTRUCTION_DETECTED
|
||||
)
|
||||
if obstruction_detected:
|
||||
return {"obstruction-detected": obstruction_detected}
|
||||
|
||||
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}
|
||||
if not obstruction_detected:
|
||||
return {}
|
||||
return {"obstruction-detected": obstruction_detected}
|
||||
|
|
|
@ -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}
|
||||
if not self.is_group:
|
||||
return {}
|
||||
return {ATTR_IS_HUE_GROUP: self.is_group}
|
||||
|
|
|
@ -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
|
||||
|
||||
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."""
|
||||
|
|
|
@ -415,12 +415,12 @@ class ManualMQTTAlarm(alarm.AlarmControlPanelEntity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
if self.state == STATE_ALARM_PENDING:
|
||||
if self.state != STATE_ALARM_PENDING:
|
||||
return {}
|
||||
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."""
|
||||
|
|
|
@ -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}
|
||||
if not cube.is_thermostat(device):
|
||||
return {}
|
||||
return {ATTR_VALVE_POSITION: device.valve_position}
|
||||
|
||||
def update(self):
|
||||
"""Get latest data from MAX! Cube."""
|
||||
|
|
|
@ -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}
|
||||
if not mfg:
|
||||
return {}
|
||||
return {"manufacturer": mfg}
|
||||
|
|
|
@ -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}
|
||||
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}
|
||||
if self._brightness is None:
|
||||
return {}
|
||||
return {ATTR_BRIGHTNESS: self._brightness}
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
|
|
|
@ -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}
|
||||
if not self._last_detection:
|
||||
return {}
|
||||
return {"last_person": self._last_detection}
|
||||
|
|
|
@ -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"):
|
||||
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,
|
||||
}
|
||||
return {}
|
||||
|
||||
@property
|
||||
def current_power_w(self):
|
||||
|
|
|
@ -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}
|
||||
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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue