Add Charging sensor to Tessie (#108205)

This commit is contained in:
Brett Adams 2024-02-02 22:21:13 +10:00 committed by GitHub
parent 90ec361fc9
commit e328d3ec5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 94 additions and 1 deletions

View File

@ -41,6 +41,7 @@ DESCRIPTIONS: tuple[TessieBinarySensorEntityDescription, ...] = (
key="charge_state_charging_state",
device_class=BinarySensorDeviceClass.BATTERY_CHARGING,
is_on=lambda x: x == "Charging",
entity_registry_enabled_default=False,
),
TessieBinarySensorEntityDescription(
key="charge_state_preconditioning_enabled",

View File

@ -68,3 +68,13 @@ class TessieChargeCableLockStates(StrEnum):
ENGAGED = "Engaged"
DISENGAGED = "Disengaged"
TessieChargeStates = {
"Starting": "starting",
"Charging": "charging",
"Stopped": "stopped",
"Complete": "complete",
"Disconnected": "disconnected",
"NoPower": "no_power",
}

View File

@ -32,7 +32,7 @@ from homeassistant.helpers.typing import StateType
from homeassistant.util import dt as dt_util
from homeassistant.util.variance import ignore_variance
from .const import DOMAIN
from .const import DOMAIN, TessieChargeStates
from .coordinator import TessieStateUpdateCoordinator
from .entity import TessieEntity
@ -54,6 +54,13 @@ class TessieSensorEntityDescription(SensorEntityDescription):
DESCRIPTIONS: tuple[TessieSensorEntityDescription, ...] = (
TessieSensorEntityDescription(
key="charge_state_charging_state",
icon="mdi:ev-station",
options=list(TessieChargeStates.values()),
device_class=SensorDeviceClass.ENUM,
value_fn=lambda value: TessieChargeStates[cast(str, value)],
),
TessieSensorEntityDescription(
key="charge_state_usable_battery_level",
state_class=SensorStateClass.MEASUREMENT,

View File

@ -67,6 +67,17 @@
}
},
"sensor": {
"charge_state_charging_state": {
"name": "Charging",
"state": {
"starting": "Starting",
"charging": "Charging",
"disconnected": "Disconnected",
"stopped": "Stopped",
"complete": "Complete",
"no_power": "No power"
}
},
"charge_state_usable_battery_level": {
"name": "Battery level"
},

View File

@ -347,6 +347,68 @@
'state': '224',
})
# ---
# name: test_sensors[sensor.test_charging-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'options': list([
'starting',
'charging',
'stopped',
'complete',
'disconnected',
'no_power',
]),
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.test_charging',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.ENUM: 'enum'>,
'original_icon': 'mdi:ev-station',
'original_name': 'Charging',
'platform': 'tessie',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'charge_state_charging_state',
'unique_id': 'VINVINVIN-charge_state_charging_state',
'unit_of_measurement': None,
})
# ---
# name: test_sensors[sensor.test_charging-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'enum',
'friendly_name': 'Test Charging',
'icon': 'mdi:ev-station',
'options': list([
'starting',
'charging',
'stopped',
'complete',
'disconnected',
'no_power',
]),
}),
'context': <ANY>,
'entity_id': 'sensor.test_charging',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'charging',
})
# ---
# name: test_sensors[sensor.test_destination-entry]
EntityRegistryEntrySnapshot({
'aliases': set({

View File

@ -1,4 +1,5 @@
"""Test the Tessie binary sensor platform."""
import pytest
from syrupy import SnapshotAssertion
from homeassistant.const import Platform
@ -8,6 +9,7 @@ from homeassistant.helpers import entity_registry as er
from .common import assert_entities, setup_platform
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_binary_sensors(
hass: HomeAssistant, snapshot: SnapshotAssertion, entity_registry: er.EntityRegistry
) -> None: