mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Fix bmw connected drive door_lock_state attribute error (#32074)
* Fix for door_lock_state attribute error * Updates based on review comments * Remove update_time * Remove update time in lock * Remove update time in sensor * Remove unused variable * Change return for device_state_attributes
This commit is contained in:
parent
908ae23738
commit
765882fc4d
@ -120,7 +120,6 @@ class BMWConnectedDriveAccount:
|
||||
self, username: str, password: str, region_str: str, name: str, read_only
|
||||
) -> None:
|
||||
"""Initialize account."""
|
||||
|
||||
region = get_region_from_name(region_str)
|
||||
|
||||
self.read_only = read_only
|
||||
|
@ -4,9 +4,10 @@ import logging
|
||||
from bimmer_connected.state import ChargingState, LockState
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||
from homeassistant.const import LENGTH_KILOMETERS
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, LENGTH_KILOMETERS
|
||||
|
||||
from . import DOMAIN as BMW_DOMAIN
|
||||
from .const import ATTRIBUTION
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -107,7 +108,10 @@ class BMWConnectedDriveSensor(BinarySensorDevice):
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the binary sensor."""
|
||||
vehicle_state = self._vehicle.state
|
||||
result = {"car": self._vehicle.name}
|
||||
result = {
|
||||
"car": self._vehicle.name,
|
||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
||||
}
|
||||
|
||||
if self._attribute == "lids":
|
||||
for lid in vehicle_state.lids:
|
||||
@ -143,7 +147,6 @@ class BMWConnectedDriveSensor(BinarySensorDevice):
|
||||
|
||||
def update(self):
|
||||
"""Read new state data from the library."""
|
||||
|
||||
vehicle_state = self._vehicle.state
|
||||
|
||||
# device class opening: On means open, Off means closed
|
||||
@ -152,7 +155,7 @@ class BMWConnectedDriveSensor(BinarySensorDevice):
|
||||
self._state = not vehicle_state.all_lids_closed
|
||||
if self._attribute == "windows":
|
||||
self._state = not vehicle_state.all_windows_closed
|
||||
# device class safety: On means unsafe, Off means safe
|
||||
# device class lock: On means unlocked, Off means locked
|
||||
if self._attribute == "door_lock_state":
|
||||
# Possible values: LOCKED, SECURED, SELECTIVE_LOCKED, UNLOCKED
|
||||
self._state = vehicle_state.door_lock_state not in [
|
||||
|
2
homeassistant/components/bmw_connected_drive/const.py
Normal file
2
homeassistant/components/bmw_connected_drive/const.py
Normal file
@ -0,0 +1,2 @@
|
||||
"""Const file for the BMW Connected Drive integration."""
|
||||
ATTRIBUTION = "Data provided by BMW Connected Drive"
|
@ -4,10 +4,12 @@ import logging
|
||||
from bimmer_connected.state import LockState
|
||||
|
||||
from homeassistant.components.lock import LockDevice
|
||||
from homeassistant.const import STATE_LOCKED, STATE_UNLOCKED
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, STATE_LOCKED, STATE_UNLOCKED
|
||||
|
||||
from . import DOMAIN as BMW_DOMAIN
|
||||
from .const import ATTRIBUTION
|
||||
|
||||
DOOR_LOCK_STATE = "door_lock_state"
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -36,6 +38,9 @@ class BMWLock(LockDevice):
|
||||
self._unique_id = f"{self._vehicle.vin}-{self._attribute}"
|
||||
self._sensor_name = sensor_name
|
||||
self._state = None
|
||||
self.door_lock_state_available = (
|
||||
DOOR_LOCK_STATE in self._vehicle.available_attributes
|
||||
)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
@ -59,10 +64,14 @@ class BMWLock(LockDevice):
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the lock."""
|
||||
vehicle_state = self._vehicle.state
|
||||
return {
|
||||
result = {
|
||||
"car": self._vehicle.name,
|
||||
"door_lock_state": vehicle_state.door_lock_state.value,
|
||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
||||
}
|
||||
if self.door_lock_state_available:
|
||||
result["door_lock_state"] = vehicle_state.door_lock_state.value
|
||||
result["last_update_reason"] = vehicle_state.last_update_reason
|
||||
return result
|
||||
|
||||
@property
|
||||
def is_locked(self):
|
||||
@ -89,7 +98,6 @@ class BMWLock(LockDevice):
|
||||
|
||||
def update(self):
|
||||
"""Update state of the lock."""
|
||||
|
||||
_LOGGER.debug("%s: updating data for %s", self._vehicle.name, self._attribute)
|
||||
vehicle_state = self._vehicle.state
|
||||
|
||||
|
@ -4,6 +4,7 @@ import logging
|
||||
from bimmer_connected.state import ChargingState
|
||||
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
CONF_UNIT_SYSTEM_IMPERIAL,
|
||||
LENGTH_KILOMETERS,
|
||||
LENGTH_MILES,
|
||||
@ -16,6 +17,7 @@ from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.icon import icon_for_battery_level
|
||||
|
||||
from . import DOMAIN as BMW_DOMAIN
|
||||
from .const import ATTRIBUTION
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -101,7 +103,6 @@ class BMWConnectedDriveSensor(Entity):
|
||||
@property
|
||||
def icon(self):
|
||||
"""Icon to use in the frontend, if any."""
|
||||
|
||||
vehicle_state = self._vehicle.state
|
||||
charging_state = vehicle_state.charging_status in [ChargingState.CHARGING]
|
||||
|
||||
@ -130,7 +131,10 @@ class BMWConnectedDriveSensor(Entity):
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the sensor."""
|
||||
return {"car": self._vehicle.name}
|
||||
return {
|
||||
"car": self._vehicle.name,
|
||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
||||
}
|
||||
|
||||
def update(self) -> None:
|
||||
"""Read new state data from the library."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user