Skip to content

Commit

Permalink
Remove suggested_unit_of_measurement attributes (#292)
Browse files Browse the repository at this point in the history
* 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 e7003f4.

* 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>
  • Loading branch information
ajain-93 and CM000n authored Aug 23, 2024
1 parent ce06bf8 commit 2468159
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion custom_components/toyota/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
31 changes: 23 additions & 8 deletions custom_components/toyota/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,73 +216,85 @@ 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
and vehicle._vehicle_info.extended_capabilities.fuel_range_available,
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,
),
]

Expand All @@ -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
)

Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 2468159

Please sign in to comment.