Add additional sensors to ecoforest integration (#100681)

* add ecoforest additional sensors

* add ecoforest additional sensors

* use StateType

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* use StateType

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* update cpu temp translation

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* use common translation

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* use common on translation

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* use common standby translation

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* update strings

* update strings

* import state type

* relabel preheating

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* add cpu temp disable by default

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
pull/100690/head
Pedro Januário 2023-09-22 10:08:09 +01:00 committed by GitHub
parent cd30286913
commit 86a692bb22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 79 additions and 3 deletions

View File

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

View File

@ -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"