code correction

This commit is contained in:
vincent committed 2024-02-20 15:54:22 +01:00
1 parent 93d8b339ec
commit 6c6b035cf5
7 files changed
+245 -238

No files matched your search

+65 -9
View File
@@ -19,7 +19,10 @@ from .const import (
DOMAIN
)
from homeassistant.const import UnitOfTime
from .koolnova.device import Koolnova
from .koolnova.device import (
Koolnova,
Engine,
)
_LOGGER = logging.getLogger(__name__)
@@ -36,12 +39,11 @@ async def async_setup_entry(hass: HomeAssistant,
entities = [
DiagnosticsSensor(device, "Device", entry.data),
DiagnosticsSensor(device, "Address", entry.data),
DiagnosticsSensor(device, "Baudrate", entry.data),
DiagnosticsSensor(device, "Sizebyte", entry.data),
DiagnosticsSensor(device, "Parity", entry.data),
DiagnosticsSensor(device, "Stopbits", entry.data),
DiagnosticsSensor(device, "Timeout", entry.data),
DiagModbusSensor(device, entry.data),
]
for engine in device.engines:
_LOGGER.debug("Engine: {}".format(engine))
entities.append(DiagEngineSensor(device, engine))
async_add_entities(entities)
class DiagnosticsSensor(SensorEntity):
@@ -63,9 +65,63 @@ class DiagnosticsSensor(SensorEntity):
self._attr_unique_id = f"{DOMAIN}-{name}-sensor"
self._attr_native_value = entry_infos.get(name)
async def async_update(self):
""" Retreive latest state. """
_LOGGER.debug("[DIAG SENSOR] call async_update")
@property
def icon(self) -> str | None:
return "mdi:monitor"
@property
def should_poll(self) -> bool:
""" Do not poll for those entities """
return False
class DiagModbusSensor(SensorEntity):
# pylint: disable = too-many-instance-attributes
""" Representation of a Sensor """
_attr_entity_category: EntityCategory | None = EntityCategory.DIAGNOSTIC
def __init__(self,
device: Koolnova, # pylint: disable=unused-argument,
entry_infos, # pylint: disable=unused-argument
) -> None:
""" Class constructor """
self._device = device
self._attr_name = f"{device.name} Modbus RTU"
self._attr_entity_registry_enabled_default = True
self._attr_device_info = self._device.device_info
self._attr_unique_id = f"{DOMAIN}-Modbus-RTU-sensor"
self._attr_native_value = "{} {}{}{}".format(entry_infos.get("Baudrate"),
entry_infos.get("Sizebyte"),
entry_infos.get("Parity")[0],
entry_infos.get("Stopbits"))
@property
def icon(self) -> str | None:
return "mdi:monitor"
@property
def should_poll(self) -> bool:
""" Do not poll for those entities """
return False
class DiagEngineSensor(SensorEntity):
# pylint: disable = too-many-instance-attributes
""" Representation of a Sensor """
_attr_entity_category: EntityCategory | None = EntityCategory.DIAGNOSTIC
def __init__(self,
device: Koolnova, # pylint: disable=unused-argument
engine: Engine, # pylint: disable=unused-argument
) -> None:
""" Class constructor """
self._device = device
self._engine = engine
self._attr_name = f"{device.name} Engine AC{engine.engine_id} Throughput"
self._attr_entity_registry_enabled_default = True
self._attr_device_info = self._device.device_info
self._attr_unique_id = f"{DOMAIN}-Engine-AC{engine.engine_id}-throughput-sensor"
self._attr_native_value = f"TEST"
@property
def icon(self) -> str | None: