diff --git a/custom_components/bmw_connected_drive/binary_sensor.py b/custom_components/bmw_connected_drive/binary_sensor.py index 3b2027b..8f7f554 100644 --- a/custom_components/bmw_connected_drive/binary_sensor.py +++ b/custom_components/bmw_connected_drive/binary_sensor.py @@ -253,6 +253,7 @@ def __init__( def update(self) -> None: """Read new state data from the library.""" + _LOGGER.debug("Updating binary sensors of %s", self._vehicle.name) vehicle_state = self._vehicle.status result = self._attrs.copy() diff --git a/custom_components/bmw_connected_drive/device_tracker.py b/custom_components/bmw_connected_drive/device_tracker.py index 4d61482..d17920f 100644 --- a/custom_components/bmw_connected_drive/device_tracker.py +++ b/custom_components/bmw_connected_drive/device_tracker.py @@ -79,6 +79,7 @@ def source_type(self) -> Literal["gps"]: def update(self) -> None: """Update state of the decvice tracker.""" + _LOGGER.debug("Updating device tracker of %s", self._vehicle.name) self._attr_extra_state_attributes = self._attrs self._location = ( self._vehicle.status.gps_position diff --git a/custom_components/bmw_connected_drive/lock.py b/custom_components/bmw_connected_drive/lock.py index 0833359..fdd7a83 100644 --- a/custom_components/bmw_connected_drive/lock.py +++ b/custom_components/bmw_connected_drive/lock.py @@ -78,7 +78,7 @@ def unlock(self, **kwargs: Any) -> None: def update(self) -> None: """Update state of the lock.""" - _LOGGER.debug("%s: updating data for %s", self._vehicle.name, self._attribute) + _LOGGER.debug("Updating lock data for '%s' of %s", self._attribute, self._vehicle.name) vehicle_state = self._vehicle.status if not self.door_lock_state_available: self._attr_is_locked = None diff --git a/custom_components/bmw_connected_drive/manifest.json b/custom_components/bmw_connected_drive/manifest.json index 15ff1f1..c1d0cf1 100644 --- a/custom_components/bmw_connected_drive/manifest.json +++ b/custom_components/bmw_connected_drive/manifest.json @@ -1,7 +1,7 @@ { "domain": "bmw_connected_drive", "name": "BMW Connected Drive", - "version": "20211115.2", + "version": "20211116.2", "documentation": "https://www.home-assistant.io/integrations/bmw_connected_drive", "requirements": ["bimmer_connected==0.8.0.0b7"], "codeowners": ["@gerard33", "@rikroe"], diff --git a/custom_components/bmw_connected_drive/sensor.py b/custom_components/bmw_connected_drive/sensor.py index ad2987b..9acc45d 100644 --- a/custom_components/bmw_connected_drive/sensor.py +++ b/custom_components/bmw_connected_drive/sensor.py @@ -140,9 +140,8 @@ async def async_setup_entry( BMWConnectedDriveSensor( account, vehicle, description, unit_system ) - for attribute_name in vehicle.drive_train_attributes - if attribute_name in vehicle.available_attributes - and (description := SENSOR_TYPES.get(attribute_name)) + for attribute_name in vehicle.available_attributes + if (description := SENSOR_TYPES.get(attribute_name)) ] ) @@ -181,7 +180,7 @@ def __init__( def update(self) -> None: """Read new state data from the library.""" - _LOGGER.debug("Updating %s", self._vehicle.name) + _LOGGER.debug("Updating sensors of %s", self._vehicle.name) vehicle_state = self._vehicle.status sensor_key = self.entity_description.key sensor_value = None @@ -190,34 +189,29 @@ def update(self) -> None: sensor_value = getattr(vehicle_state, sensor_key).value elif self._service is None: sensor_value = getattr(vehicle_state, sensor_key) - if sensor_key in ["remaining_range_electric"]: - _LOGGER.debug( - "sensor value for '%s' is '%s'. Source data: '%s'", - sensor_key, - sensor_value, vehicle_state.status["fuelIndicators"] - ) - - if sensor_key in ["charging_level_hv"]: - _LOGGER.debug( - "sensor value for '%s' is '%s'. Source data: '%s'", - sensor_key, - sensor_value, - vehicle_state.properties["electricRangeAndStatus"]["chargePercentage"] - ) if isinstance(sensor_value, tuple): sensor_unit = UNIT_MAP.get(sensor_value[1], sensor_value[1]) - if sensor_unit == self.unit_of_measurement: - sensor_value = sensor_value[0] - elif self.unit_of_measurement in [LENGTH_KILOMETERS, LENGTH_MILES]: + sensor_value = sensor_value[0] + sensor_value_org = sensor_value + + if self.unit_of_measurement in [LENGTH_KILOMETERS, LENGTH_MILES]: sensor_value = round( - self.hass.config.units.length(sensor_value[0], sensor_unit) + self.hass.config.units.length(sensor_value, sensor_unit) ) elif self.unit_of_measurement in [VOLUME_LITERS, VOLUME_GALLONS]: sensor_value = round( - self.hass.config.units.volume(sensor_value[0], sensor_unit) + self.hass.config.units.volume(sensor_value, sensor_unit) ) - self._attr_native_value = sensor_value + + _LOGGER.debug( + "UoM Conversion for %s. HA: %s %s, Vehicle: %s %s.", + sensor_key, + sensor_value, self.unit_of_measurement, + sensor_value_org, sensor_unit + ) + + self._attr_native_value = sensor_value if sensor_key == "charging_level_hv": charging_state = self._vehicle.status.charging_status in { @@ -226,3 +220,4 @@ def update(self) -> None: self._attr_icon = icon_for_battery_level( battery_level=vehicle_state.charging_level_hv, charging=charging_state ) +