mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Fix attributes not showing after using entity class attributes (#54558)
This commit is contained in:
parent
84f568abb1
commit
50bcb3f821
@ -335,11 +335,6 @@ class BMWConnectedDriveBaseEntity(Entity):
|
|||||||
"manufacturer": vehicle.attributes.get("brand"),
|
"manufacturer": vehicle.attributes.get("brand"),
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
|
||||||
def extra_state_attributes(self):
|
|
||||||
"""Return the state attributes of the sensor."""
|
|
||||||
return self._attrs
|
|
||||||
|
|
||||||
def update_callback(self):
|
def update_callback(self):
|
||||||
"""Schedule a state update."""
|
"""Schedule a state update."""
|
||||||
self.schedule_update_ha_state(True)
|
self.schedule_update_ha_state(True)
|
||||||
|
@ -85,54 +85,38 @@ class BMWConnectedDriveSensor(BMWConnectedDriveBaseEntity, BinarySensorEntity):
|
|||||||
def update(self):
|
def update(self):
|
||||||
"""Read new state data from the library."""
|
"""Read new state data from the library."""
|
||||||
vehicle_state = self._vehicle.state
|
vehicle_state = self._vehicle.state
|
||||||
|
result = self._attrs.copy()
|
||||||
|
|
||||||
# device class opening: On means open, Off means closed
|
# device class opening: On means open, Off means closed
|
||||||
if self._attribute == "lids":
|
if self._attribute == "lids":
|
||||||
_LOGGER.debug("Status of lid: %s", vehicle_state.all_lids_closed)
|
_LOGGER.debug("Status of lid: %s", vehicle_state.all_lids_closed)
|
||||||
self._attr_state = not vehicle_state.all_lids_closed
|
self._attr_is_on = not vehicle_state.all_lids_closed
|
||||||
if self._attribute == "windows":
|
|
||||||
self._attr_state = not vehicle_state.all_windows_closed
|
|
||||||
# device class lock: On means unlocked, Off means locked
|
|
||||||
if self._attribute == "door_lock_state":
|
|
||||||
# Possible values: LOCKED, SECURED, SELECTIVE_LOCKED, UNLOCKED
|
|
||||||
self._attr_state = vehicle_state.door_lock_state not in [
|
|
||||||
LockState.LOCKED,
|
|
||||||
LockState.SECURED,
|
|
||||||
]
|
|
||||||
# device class light: On means light detected, Off means no light
|
|
||||||
if self._attribute == "lights_parking":
|
|
||||||
self._attr_state = vehicle_state.are_parking_lights_on
|
|
||||||
# device class problem: On means problem detected, Off means no problem
|
|
||||||
if self._attribute == "condition_based_services":
|
|
||||||
self._attr_state = not vehicle_state.are_all_cbs_ok
|
|
||||||
if self._attribute == "check_control_messages":
|
|
||||||
self._attr_state = vehicle_state.has_check_control_messages
|
|
||||||
# device class power: On means power detected, Off means no power
|
|
||||||
if self._attribute == "charging_status":
|
|
||||||
self._attr_state = vehicle_state.charging_status in [ChargingState.CHARGING]
|
|
||||||
# device class plug: On means device is plugged in,
|
|
||||||
# Off means device is unplugged
|
|
||||||
if self._attribute == "connection_status":
|
|
||||||
self._attr_state = vehicle_state.connection_status == "CONNECTED"
|
|
||||||
|
|
||||||
vehicle_state = self._vehicle.state
|
|
||||||
result = self._attrs.copy()
|
|
||||||
|
|
||||||
if self._attribute == "lids":
|
|
||||||
for lid in vehicle_state.lids:
|
for lid in vehicle_state.lids:
|
||||||
result[lid.name] = lid.state.value
|
result[lid.name] = lid.state.value
|
||||||
elif self._attribute == "windows":
|
elif self._attribute == "windows":
|
||||||
|
self._attr_is_on = not vehicle_state.all_windows_closed
|
||||||
for window in vehicle_state.windows:
|
for window in vehicle_state.windows:
|
||||||
result[window.name] = window.state.value
|
result[window.name] = window.state.value
|
||||||
|
# device class lock: On means unlocked, Off means locked
|
||||||
elif self._attribute == "door_lock_state":
|
elif self._attribute == "door_lock_state":
|
||||||
|
# Possible values: LOCKED, SECURED, SELECTIVE_LOCKED, UNLOCKED
|
||||||
|
self._attr_is_on = vehicle_state.door_lock_state not in [
|
||||||
|
LockState.LOCKED,
|
||||||
|
LockState.SECURED,
|
||||||
|
]
|
||||||
result["door_lock_state"] = vehicle_state.door_lock_state.value
|
result["door_lock_state"] = vehicle_state.door_lock_state.value
|
||||||
result["last_update_reason"] = vehicle_state.last_update_reason
|
result["last_update_reason"] = vehicle_state.last_update_reason
|
||||||
|
# device class light: On means light detected, Off means no light
|
||||||
elif self._attribute == "lights_parking":
|
elif self._attribute == "lights_parking":
|
||||||
|
self._attr_is_on = vehicle_state.are_parking_lights_on
|
||||||
result["lights_parking"] = vehicle_state.parking_lights.value
|
result["lights_parking"] = vehicle_state.parking_lights.value
|
||||||
|
# device class problem: On means problem detected, Off means no problem
|
||||||
elif self._attribute == "condition_based_services":
|
elif self._attribute == "condition_based_services":
|
||||||
|
self._attr_is_on = not vehicle_state.are_all_cbs_ok
|
||||||
for report in vehicle_state.condition_based_services:
|
for report in vehicle_state.condition_based_services:
|
||||||
result.update(self._format_cbs_report(report))
|
result.update(self._format_cbs_report(report))
|
||||||
elif self._attribute == "check_control_messages":
|
elif self._attribute == "check_control_messages":
|
||||||
|
self._attr_is_on = vehicle_state.has_check_control_messages
|
||||||
check_control_messages = vehicle_state.check_control_messages
|
check_control_messages = vehicle_state.check_control_messages
|
||||||
has_check_control_messages = vehicle_state.has_check_control_messages
|
has_check_control_messages = vehicle_state.has_check_control_messages
|
||||||
if has_check_control_messages:
|
if has_check_control_messages:
|
||||||
@ -142,13 +126,18 @@ class BMWConnectedDriveSensor(BMWConnectedDriveBaseEntity, BinarySensorEntity):
|
|||||||
result["check_control_messages"] = cbs_list
|
result["check_control_messages"] = cbs_list
|
||||||
else:
|
else:
|
||||||
result["check_control_messages"] = "OK"
|
result["check_control_messages"] = "OK"
|
||||||
|
# device class power: On means power detected, Off means no power
|
||||||
elif self._attribute == "charging_status":
|
elif self._attribute == "charging_status":
|
||||||
|
self._attr_is_on = vehicle_state.charging_status in [ChargingState.CHARGING]
|
||||||
result["charging_status"] = vehicle_state.charging_status.value
|
result["charging_status"] = vehicle_state.charging_status.value
|
||||||
result["last_charging_end_result"] = vehicle_state.last_charging_end_result
|
result["last_charging_end_result"] = vehicle_state.last_charging_end_result
|
||||||
|
# device class plug: On means device is plugged in,
|
||||||
|
# Off means device is unplugged
|
||||||
elif self._attribute == "connection_status":
|
elif self._attribute == "connection_status":
|
||||||
|
self._attr_is_on = vehicle_state.connection_status == "CONNECTED"
|
||||||
result["connection_status"] = vehicle_state.connection_status
|
result["connection_status"] = vehicle_state.connection_status
|
||||||
|
|
||||||
self._attr_extra_state_attributes = sorted(result.items())
|
self._attr_extra_state_attributes = result
|
||||||
|
|
||||||
def _format_cbs_report(self, report):
|
def _format_cbs_report(self, report):
|
||||||
result = {}
|
result = {}
|
||||||
|
@ -59,6 +59,7 @@ class BMWDeviceTracker(BMWConnectedDriveBaseEntity, TrackerEntity):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update state of the decvice tracker."""
|
"""Update state of the decvice tracker."""
|
||||||
|
self._attr_extra_state_attributes = self._attrs
|
||||||
self._location = (
|
self._location = (
|
||||||
self._vehicle.state.gps_position
|
self._vehicle.state.gps_position
|
||||||
if self._vehicle.state.is_vehicle_tracking_enabled
|
if self._vehicle.state.is_vehicle_tracking_enabled
|
||||||
|
Loading…
x
Reference in New Issue
Block a user