From 2468159f750bb5208fa6128415bb172b0ffe887d Mon Sep 17 00:00:00 2001 From: Arnav Jain Date: Fri, 23 Aug 2024 19:32:38 +0200 Subject: [PATCH] Remove `suggested_unit_of_measurement` attributes (#292) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove `suggested_unit_of_measurement` attributes Solves #273 and makes it work in 2024.7 * Revert "Remove `suggested_unit_of_measurement` attributes" This reverts commit e7003f474bd573ebe6377a740ec69d7079528fcb. * add explicit suggested_unit_of_measurement * set explicit `native_unit` and `suggested_unit` * bump version to 2.0.5 --------- Co-authored-by: Simon Hörrle <7945681+CM000n@users.noreply.github.com> --- custom_components/toyota/manifest.json | 2 +- custom_components/toyota/sensor.py | 31 +++++++++++++++++++------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/custom_components/toyota/manifest.json b/custom_components/toyota/manifest.json index 2e34b07..22cca65 100644 --- a/custom_components/toyota/manifest.json +++ b/custom_components/toyota/manifest.json @@ -8,5 +8,5 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/DurgNomis-drol/ha_toyota/issues", "requirements": ["mytoyota>=2.1.4,<3.0", "arrow"], - "version": "v2.0.4" + "version": "v2.0.5" } diff --git a/custom_components/toyota/sensor.py b/custom_components/toyota/sensor.py index 97cf295..a77421b 100644 --- a/custom_components/toyota/sensor.py +++ b/custom_components/toyota/sensor.py @@ -216,42 +216,49 @@ async def async_setup_entry( VIN_ENTITY_DESCRIPTION, ToyotaSensor, None, + None, ), ( vehicle._vehicle_info.extended_capabilities.telemetry_capable, ODOMETER_ENTITY_DESCRIPTION, ToyotaSensor, UnitOfLength.KILOMETERS if metric_values is True else UnitOfLength.MILES, + UnitOfLength.KILOMETERS if metric_values is True else UnitOfLength.MILES, ), ( vehicle._vehicle_info.extended_capabilities.fuel_level_available, FUEL_LEVEL_ENTITY_DESCRIPTION, ToyotaSensor, PERCENTAGE, + None, ), ( vehicle._vehicle_info.extended_capabilities.fuel_range_available, FUEL_RANGE_ENTITY_DESCRIPTION, ToyotaSensor, UnitOfLength.KILOMETERS if metric_values is True else UnitOfLength.MILES, + UnitOfLength.KILOMETERS if metric_values is True else UnitOfLength.MILES, ), ( vehicle._vehicle_info.extended_capabilities.econnect_vehicle_status_capable, BATTERY_LEVEL_ENTITY_DESCRIPTION, ToyotaSensor, PERCENTAGE, + PERCENTAGE, ), ( vehicle._vehicle_info.extended_capabilities.econnect_vehicle_status_capable, BATTERY_RANGE_ENTITY_DESCRIPTION, ToyotaSensor, UnitOfLength.KILOMETERS if metric_values is True else UnitOfLength.MILES, + UnitOfLength.KILOMETERS if metric_values is True else UnitOfLength.MILES, ), ( vehicle._vehicle_info.extended_capabilities.econnect_vehicle_status_capable, BATTERY_RANGE_AC_ENTITY_DESCRIPTION, ToyotaSensor, UnitOfLength.KILOMETERS if metric_values is True else UnitOfLength.MILES, + UnitOfLength.KILOMETERS if metric_values is True else UnitOfLength.MILES, ), ( vehicle._vehicle_info.extended_capabilities.econnect_vehicle_status_capable @@ -259,30 +266,35 @@ async def async_setup_entry( TOTAL_RANGE_ENTITY_DESCRIPTION, ToyotaSensor, UnitOfLength.KILOMETERS if metric_values is True else UnitOfLength.MILES, + UnitOfLength.KILOMETERS if metric_values is True else UnitOfLength.MILES, ), ( True, # TODO Unsure of the required capability STATISTICS_ENTITY_DESCRIPTIONS_DAILY, ToyotaStatisticsSensor, UnitOfLength.KILOMETERS if metric_values is True else UnitOfLength.MILES, + UnitOfLength.KILOMETERS if metric_values is True else UnitOfLength.MILES, ), ( True, # TODO Unsure of the required capability STATISTICS_ENTITY_DESCRIPTIONS_WEEKLY, ToyotaStatisticsSensor, UnitOfLength.KILOMETERS if metric_values is True else UnitOfLength.MILES, + UnitOfLength.KILOMETERS if metric_values is True else UnitOfLength.MILES, ), ( True, # TODO Unsure of the required capability STATISTICS_ENTITY_DESCRIPTIONS_MONTHLY, ToyotaStatisticsSensor, UnitOfLength.KILOMETERS if metric_values is True else UnitOfLength.MILES, + UnitOfLength.KILOMETERS if metric_values is True else UnitOfLength.MILES, ), ( True, # TODO Unsure of the required capability STATISTICS_ENTITY_DESCRIPTIONS_YEARLY, ToyotaStatisticsSensor, UnitOfLength.KILOMETERS if metric_values is True else UnitOfLength.MILES, + UnitOfLength.KILOMETERS if metric_values is True else UnitOfLength.MILES, ), ] @@ -292,9 +304,10 @@ async def async_setup_entry( entry_id=entry.entry_id, vehicle_index=index, description=description, - unit=unit, + native_unit=native_unit, + suggested_unit=suggested_unit, ) - for capability, description, sensor_type, unit in capabilities_descriptions + for capability, description, sensor_type, native_unit, suggested_unit in capabilities_descriptions # noqa: E501 if capability ) @@ -312,13 +325,14 @@ def __init__( # noqa: PLR0913 entry_id: str, vehicle_index: int, description: ToyotaSensorEntityDescription, - unit: Union[UnitOfLength, str], + native_unit: Union[UnitOfLength, str], + suggested_unit: Union[UnitOfLength, str], ) -> None: """Initialise the ToyotaSensor class.""" super().__init__(coordinator, entry_id, vehicle_index, description) self.description = description - self._attr_native_unit_of_measurement = unit - self._attr_suggested_unit_of_measurement = unit + self._attr_native_unit_of_measurement = native_unit + self._attr_suggested_unit_of_measurement = suggested_unit @property def native_value(self) -> StateType: @@ -342,13 +356,14 @@ def __init__( # noqa: PLR0913 entry_id: str, vehicle_index: int, description: ToyotaStatisticsSensorEntityDescription, - unit: Union[UnitOfLength, str], + native_unit: Union[UnitOfLength, str], + suggested_unit: Union[UnitOfLength, str], ) -> None: """Initialise the ToyotaStatisticsSensor class.""" super().__init__(coordinator, entry_id, vehicle_index, description) self.period: Literal["day", "week", "month", "year"] = description.period - self._attr_native_unit_of_measurement = unit - self._attr_suggested_unit_of_measurement = unit + self._attr_native_unit_of_measurement = native_unit + self._attr_suggested_unit_of_measurement = suggested_unit @property def native_value(self) -> StateType: