From 86a692bb22088a520212c1d540302b9e84f0c1e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Janu=C3=A1rio?= Date: Fri, 22 Sep 2023 10:08:09 +0100 Subject: [PATCH] Add additional sensors to ecoforest integration (#100681) * add ecoforest additional sensors * add ecoforest additional sensors * use StateType Co-authored-by: Joost Lekkerkerker * use StateType Co-authored-by: Joost Lekkerkerker * update cpu temp translation Co-authored-by: Joost Lekkerkerker * use common translation Co-authored-by: Joost Lekkerkerker * use common on translation Co-authored-by: Joost Lekkerkerker * use common standby translation Co-authored-by: Joost Lekkerkerker * update strings * update strings * import state type * relabel preheating Co-authored-by: Joost Lekkerkerker * add cpu temp disable by default --------- Co-authored-by: Joost Lekkerkerker --- homeassistant/components/ecoforest/sensor.py | 49 +++++++++++++++++-- .../components/ecoforest/strings.json | 33 +++++++++++++ 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/ecoforest/sensor.py b/homeassistant/components/ecoforest/sensor.py index bba0a360375..91f3138af37 100644 --- a/homeassistant/components/ecoforest/sensor.py +++ b/homeassistant/components/ecoforest/sensor.py @@ -5,7 +5,7 @@ from collections.abc import Callable from dataclasses import dataclass import logging -from pyecoforest.models.device import Device +from pyecoforest.models.device import Alarm, Device, State from homeassistant.components.sensor import ( SensorDeviceClass, @@ -16,6 +16,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback +from homeassistant.helpers.typing import StateType from .const import DOMAIN from .coordinator import EcoforestCoordinator @@ -23,12 +24,15 @@ from .entity import EcoforestEntity _LOGGER = logging.getLogger(__name__) +STATUS_TYPE = [s.value for s in State] +ALARM_TYPE = [a.value for a in Alarm] + ["none"] + @dataclass class EcoforestRequiredKeysMixin: """Mixin for required keys.""" - value_fn: Callable[[Device], float | None] + value_fn: Callable[[Device], StateType] @dataclass @@ -45,6 +49,45 @@ SENSOR_TYPES: tuple[EcoforestSensorEntityDescription, ...] = ( device_class=SensorDeviceClass.TEMPERATURE, value_fn=lambda data: data.environment_temperature, ), + EcoforestSensorEntityDescription( + key="cpu_temperature", + translation_key="cpu_temperature", + native_unit_of_measurement=UnitOfTemperature.CELSIUS, + device_class=SensorDeviceClass.TEMPERATURE, + entity_registry_enabled_default=False, + value_fn=lambda data: data.cpu_temperature, + ), + EcoforestSensorEntityDescription( + key="gas_temperature", + translation_key="gas_temperature", + native_unit_of_measurement=UnitOfTemperature.CELSIUS, + device_class=SensorDeviceClass.TEMPERATURE, + entity_registry_enabled_default=False, + value_fn=lambda data: data.gas_temperature, + ), + EcoforestSensorEntityDescription( + key="ntc_temperature", + translation_key="ntc_temperature", + native_unit_of_measurement=UnitOfTemperature.CELSIUS, + device_class=SensorDeviceClass.TEMPERATURE, + entity_registry_enabled_default=False, + value_fn=lambda data: data.ntc_temperature, + ), + EcoforestSensorEntityDescription( + key="status", + translation_key="status", + device_class=SensorDeviceClass.ENUM, + options=STATUS_TYPE, + value_fn=lambda data: data.state.value, + ), + EcoforestSensorEntityDescription( + key="alarm", + translation_key="alarm", + device_class=SensorDeviceClass.ENUM, + options=ALARM_TYPE, + icon="mdi:alert", + value_fn=lambda data: data.alarm.value if data.alarm else "none", + ), ) @@ -67,6 +110,6 @@ class EcoforestSensor(SensorEntity, EcoforestEntity): entity_description: EcoforestSensorEntityDescription @property - def native_value(self) -> float | None: + def native_value(self) -> StateType: """Return the state of the sensor.""" return self.entity_description.value_fn(self.data) diff --git a/homeassistant/components/ecoforest/strings.json b/homeassistant/components/ecoforest/strings.json index b35ff1dedf1..bd0605eab82 100644 --- a/homeassistant/components/ecoforest/strings.json +++ b/homeassistant/components/ecoforest/strings.json @@ -19,6 +19,39 @@ } }, "entity": { + "sensor": { + "cpu_temperature": { + "name": "CPU temperature" + }, + "gas_temperature": { + "name": "Gas temperature" + }, + "ntc_temperature": { + "name": "NTC probe temperature" + }, + "status": { + "name": "Status", + "state": { + "off": "[%key:common::state::off%]", + "starting": "Starting", + "pre_heating": "Pre-heating", + "on": "[%key:common::state::on%]", + "shutting_down": "Shutting down", + "stand_by": "[%key:common::state::standby%]", + "alarm": "Alarm" + } + }, + "alarm": { + "name": "Alarm", + "state": { + "air_depression": "Air depression", + "pellets": "Pellets", + "cpu_overheating": "CPU overheating", + "unkownn": "Unknown alarm", + "none": "None" + } + } + }, "number": { "power_level": { "name": "Power level"