mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Fix shift state default in Teslemetry and Tessie (#140018)
* Fix again * Fix Tessie * Update snap
This commit is contained in:
parent
82d5304b45
commit
935890e4e0
@ -68,7 +68,7 @@ class TeslemetryVehicleSensorEntityDescription(SensorEntityDescription):
|
|||||||
|
|
||||||
polling: bool = False
|
polling: bool = False
|
||||||
polling_value_fn: Callable[[StateType], StateType] = lambda x: x
|
polling_value_fn: Callable[[StateType], StateType] = lambda x: x
|
||||||
polling_available_fn: Callable[[StateType], bool] = lambda x: x is not None
|
nullable: bool = False
|
||||||
streaming_key: Signal | None = None
|
streaming_key: Signal | None = None
|
||||||
streaming_value_fn: Callable[[str | int | float], StateType] = lambda x: x
|
streaming_value_fn: Callable[[str | int | float], StateType] = lambda x: x
|
||||||
streaming_firmware: str = "2024.26"
|
streaming_firmware: str = "2024.26"
|
||||||
@ -210,7 +210,7 @@ VEHICLE_DESCRIPTIONS: tuple[TeslemetryVehicleSensorEntityDescription, ...] = (
|
|||||||
TeslemetryVehicleSensorEntityDescription(
|
TeslemetryVehicleSensorEntityDescription(
|
||||||
key="drive_state_shift_state",
|
key="drive_state_shift_state",
|
||||||
polling=True,
|
polling=True,
|
||||||
polling_available_fn=lambda x: True,
|
nullable=True,
|
||||||
polling_value_fn=lambda x: SHIFT_STATES.get(str(x), "p"),
|
polling_value_fn=lambda x: SHIFT_STATES.get(str(x), "p"),
|
||||||
streaming_key=Signal.GEAR,
|
streaming_key=Signal.GEAR,
|
||||||
streaming_value_fn=lambda x: str(ShiftState.get(x, "P")).lower(),
|
streaming_value_fn=lambda x: str(ShiftState.get(x, "P")).lower(),
|
||||||
@ -622,10 +622,10 @@ class TeslemetryStreamSensorEntity(TeslemetryVehicleStreamEntity, RestoreSensor)
|
|||||||
|
|
||||||
def _async_value_from_stream(self, value) -> None:
|
def _async_value_from_stream(self, value) -> None:
|
||||||
"""Update the value of the entity."""
|
"""Update the value of the entity."""
|
||||||
if value is None:
|
if self.entity_description.nullable or value is not None:
|
||||||
self._attr_native_value = None
|
|
||||||
else:
|
|
||||||
self._attr_native_value = self.entity_description.streaming_value_fn(value)
|
self._attr_native_value = self.entity_description.streaming_value_fn(value)
|
||||||
|
else:
|
||||||
|
self._attr_native_value = None
|
||||||
|
|
||||||
|
|
||||||
class TeslemetryVehicleSensorEntity(TeslemetryVehicleEntity, SensorEntity):
|
class TeslemetryVehicleSensorEntity(TeslemetryVehicleEntity, SensorEntity):
|
||||||
@ -644,7 +644,7 @@ class TeslemetryVehicleSensorEntity(TeslemetryVehicleEntity, SensorEntity):
|
|||||||
|
|
||||||
def _async_update_attrs(self) -> None:
|
def _async_update_attrs(self) -> None:
|
||||||
"""Update the attributes of the sensor."""
|
"""Update the attributes of the sensor."""
|
||||||
if self.entity_description.polling_available_fn(self._value):
|
if self.entity_description.nullable or self._value is not None:
|
||||||
self._attr_available = True
|
self._attr_available = True
|
||||||
self._attr_native_value = self.entity_description.polling_value_fn(
|
self._attr_native_value = self.entity_description.polling_value_fn(
|
||||||
self._value
|
self._value
|
||||||
|
@ -148,7 +148,7 @@ DESCRIPTIONS: tuple[TessieSensorEntityDescription, ...] = (
|
|||||||
key="drive_state_shift_state",
|
key="drive_state_shift_state",
|
||||||
options=["p", "d", "r", "n"],
|
options=["p", "d", "r", "n"],
|
||||||
device_class=SensorDeviceClass.ENUM,
|
device_class=SensorDeviceClass.ENUM,
|
||||||
value_fn=lambda x: x.lower() if isinstance(x, str) else x,
|
value_fn=lambda x: x.lower() if isinstance(x, str) else "p",
|
||||||
),
|
),
|
||||||
TessieSensorEntityDescription(
|
TessieSensorEntityDescription(
|
||||||
key="vehicle_state_odometer",
|
key="vehicle_state_odometer",
|
||||||
|
@ -1614,7 +1614,7 @@
|
|||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_reported': <ANY>,
|
'last_reported': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': 'unknown',
|
'state': 'p',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_sensors[sensor.test_speed-entry]
|
# name: test_sensors[sensor.test_speed-entry]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user