Add Renault hvac sensors (#65993)

* Add hvac sensors to renault

* Adjust fixtures

* Adjust tests

* Use icon_fn

* Use lambda

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2022-02-08 22:02:45 +01:00 committed by GitHub
parent 55d8314093
commit 86ab500afd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 89 additions and 3 deletions

View File

@ -1,6 +1,7 @@
"""Support for Renault binary sensors."""
from __future__ import annotations
from collections.abc import Callable
from dataclasses import dataclass
from renault_api.kamereon.enums import ChargeState, PlugState
@ -37,6 +38,8 @@ class RenaultBinarySensorEntityDescription(
):
"""Class describing Renault binary sensor entities."""
icon_fn: Callable[[RenaultBinarySensor], str] | None = None
async def async_setup_entry(
hass: HomeAssistant,
@ -68,6 +71,13 @@ class RenaultBinarySensor(
return None
return data == self.entity_description.on_value
@property
def icon(self) -> str | None:
"""Icon handling."""
if self.entity_description.icon_fn:
return self.entity_description.icon_fn(self)
return None
BINARY_SENSOR_TYPES: tuple[RenaultBinarySensorEntityDescription, ...] = (
RenaultBinarySensorEntityDescription(
@ -86,4 +96,12 @@ BINARY_SENSOR_TYPES: tuple[RenaultBinarySensorEntityDescription, ...] = (
on_key="chargingStatus",
on_value=ChargeState.CHARGE_IN_PROGRESS.value,
),
RenaultBinarySensorEntityDescription(
key="hvac_status",
coordinator="hvac_status",
icon_fn=lambda e: "mdi:fan" if e.is_on else "mdi:fan-off",
name="HVAC",
on_key="hvacStatus",
on_value="on",
),
)

View File

@ -305,6 +305,24 @@ SENSOR_TYPES: tuple[RenaultSensorEntityDescription, ...] = (
native_unit_of_measurement=TEMP_CELSIUS,
state_class=SensorStateClass.MEASUREMENT,
),
RenaultSensorEntityDescription(
key="hvac_soc_threshold",
coordinator="hvac_status",
data_key="socThreshold",
entity_class=RenaultSensor[KamereonVehicleHvacStatusData],
name="HVAC SOC Threshold",
native_unit_of_measurement=PERCENTAGE,
),
RenaultSensorEntityDescription(
key="hvac_last_activity",
coordinator="hvac_status",
device_class=SensorDeviceClass.TIMESTAMP,
data_key="lastUpdateTime",
entity_class=RenaultSensor[KamereonVehicleHvacStatusData],
entity_registry_enabled_default=False,
name="HVAC Last Activity",
value_lambda=_get_utc_value,
),
RenaultSensorEntityDescription(
key="location_last_activity",
coordinator="location",

View File

@ -54,6 +54,7 @@ FIXED_ATTRIBUTES = (
DYNAMIC_ATTRIBUTES = (ATTR_ICON,)
ICON_FOR_EMPTY_VALUES = {
"binary_sensor.reg_number_hvac": "mdi:fan-off",
"select.reg_number_charge_mode": "mdi:calendar-remove",
"sensor.reg_number_charge_state": "mdi:flash-off",
"sensor.reg_number_plug_state": "mdi:power-plug-off",
@ -89,7 +90,7 @@ MOCK_VEHICLES = {
"battery_status": "battery_status_charging.json",
"charge_mode": "charge_mode_always.json",
"cockpit": "cockpit_ev.json",
"hvac_status": "hvac_status.json",
"hvac_status": "hvac_status.1.json",
},
Platform.BINARY_SENSOR: [
{
@ -104,6 +105,12 @@ MOCK_VEHICLES = {
ATTR_STATE: STATE_ON,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_charging",
},
{
ATTR_ENTITY_ID: "binary_sensor.reg_number_hvac",
ATTR_ICON: "mdi:fan-off",
ATTR_STATE: STATE_OFF,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_hvac_status",
},
],
Platform.BUTTON: [
{
@ -209,6 +216,19 @@ MOCK_VEHICLES = {
ATTR_UNIQUE_ID: "vf1aaaaa555777999_outside_temperature",
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
},
{
ATTR_ENTITY_ID: "sensor.reg_number_hvac_soc_threshold",
ATTR_STATE: STATE_UNKNOWN,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_hvac_soc_threshold",
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_DEVICE_CLASS: SensorDeviceClass.TIMESTAMP,
ATTR_ENTITY_ID: "sensor.reg_number_hvac_last_activity",
ATTR_STATE: STATE_UNKNOWN,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_hvac_last_activity",
},
{
ATTR_DEVICE_CLASS: DEVICE_CLASS_PLUG_STATE,
ATTR_ENTITY_ID: "sensor.reg_number_plug_state",
@ -237,7 +257,7 @@ MOCK_VEHICLES = {
"battery_status": "battery_status_not_charging.json",
"charge_mode": "charge_mode_schedule.json",
"cockpit": "cockpit_ev.json",
"hvac_status": "hvac_status.json",
"hvac_status": "hvac_status.2.json",
"location": "location.json",
},
Platform.BINARY_SENSOR: [
@ -253,6 +273,12 @@ MOCK_VEHICLES = {
ATTR_STATE: STATE_OFF,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_charging",
},
{
ATTR_ENTITY_ID: "binary_sensor.reg_number_hvac",
ATTR_ICON: "mdi:fan-off",
ATTR_STATE: STATE_OFF,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_hvac_status",
},
],
Platform.BUTTON: [
{
@ -360,11 +386,24 @@ MOCK_VEHICLES = {
{
ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
ATTR_ENTITY_ID: "sensor.reg_number_outside_temperature",
ATTR_STATE: "8.0",
ATTR_STATE: STATE_UNKNOWN,
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_outside_temperature",
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
},
{
ATTR_ENTITY_ID: "sensor.reg_number_hvac_soc_threshold",
ATTR_STATE: "30.0",
ATTR_UNIQUE_ID: "vf1aaaaa555777999_hvac_soc_threshold",
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_DEVICE_CLASS: SensorDeviceClass.TIMESTAMP,
ATTR_ENTITY_ID: "sensor.reg_number_hvac_last_activity",
ATTR_STATE: "2020-12-03T00:00:00+00:00",
ATTR_UNIQUE_ID: "vf1aaaaa555777999_hvac_last_activity",
},
{
ATTR_DEVICE_CLASS: DEVICE_CLASS_PLUG_STATE,
ATTR_ENTITY_ID: "sensor.reg_number_plug_state",

View File

@ -0,0 +1,11 @@
{
"data": {
"type": "Car",
"id": "VF1AAAAA555777999",
"attributes": {
"socThreshold": 30.0,
"hvacStatus": "off",
"lastUpdateTime": "2020-12-03T00:00:00Z"
}
}
}