diff --git a/homeassistant/components/bmw_connected_drive/__init__.py b/homeassistant/components/bmw_connected_drive/__init__.py index 6e7723b16ec..273bac8ef0e 100644 --- a/homeassistant/components/bmw_connected_drive/__init__.py +++ b/homeassistant/components/bmw_connected_drive/__init__.py @@ -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 diff --git a/homeassistant/components/bmw_connected_drive/binary_sensor.py b/homeassistant/components/bmw_connected_drive/binary_sensor.py index 591cdadda35..fc3069f284c 100644 --- a/homeassistant/components/bmw_connected_drive/binary_sensor.py +++ b/homeassistant/components/bmw_connected_drive/binary_sensor.py @@ -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 [ diff --git a/homeassistant/components/bmw_connected_drive/const.py b/homeassistant/components/bmw_connected_drive/const.py new file mode 100644 index 00000000000..d1a44b5e5c9 --- /dev/null +++ b/homeassistant/components/bmw_connected_drive/const.py @@ -0,0 +1,2 @@ +"""Const file for the BMW Connected Drive integration.""" +ATTRIBUTION = "Data provided by BMW Connected Drive" diff --git a/homeassistant/components/bmw_connected_drive/lock.py b/homeassistant/components/bmw_connected_drive/lock.py index 5323e94c1c3..7d4ad420af4 100644 --- a/homeassistant/components/bmw_connected_drive/lock.py +++ b/homeassistant/components/bmw_connected_drive/lock.py @@ -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 diff --git a/homeassistant/components/bmw_connected_drive/sensor.py b/homeassistant/components/bmw_connected_drive/sensor.py index 30c12d7d7a0..d7eec8b9479 100644 --- a/homeassistant/components/bmw_connected_drive/sensor.py +++ b/homeassistant/components/bmw_connected_drive/sensor.py @@ -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."""