From 297c45ed06e4180d308a23b4d7666b29d1c31436 Mon Sep 17 00:00:00 2001 From: Martin Klemm Date: Wed, 1 Apr 2026 14:16:04 +0200 Subject: [PATCH 1/2] Fixed sensor device classes for power sensors. Removed unnecessary imports Replaced legacy epochmilliseconds with standard way of doing this in HA Fixed exception logs Renamed state to native_value --- custom_components/saj_esolar/sensor.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/custom_components/saj_esolar/sensor.py b/custom_components/saj_esolar/sensor.py index 5c213e1..3ff8ef9 100644 --- a/custom_components/saj_esolar/sensor.py +++ b/custom_components/saj_esolar/sensor.py @@ -13,7 +13,6 @@ from typing import Final import aiohttp -import async_timeout import voluptuous as vol from homeassistant.components.sensor import ( @@ -34,7 +33,6 @@ ) CONF_PLANT_ID: Final = "plant_id" -from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity from homeassistant.util import Throttle, dt @@ -147,7 +145,7 @@ def add_years(d, years): name="nowPower", icon="mdi:solar-power", native_unit_of_measurement=UnitOfPower.WATT, - device_class=SensorDeviceClass.ENERGY, + device_class=SensorDeviceClass.POWER, ), SensorEntityDescription( key="runningState", @@ -281,14 +279,14 @@ def add_years(d, years): name="peakPower", icon="mdi:solar-panel", native_unit_of_measurement=UnitOfPower.WATT, - device_class=SensorDeviceClass.ENERGY, + device_class=SensorDeviceClass.POWER, ), SensorEntityDescription( key="systemPower", name="systemPower", icon="mdi:solar-panel", native_unit_of_measurement=UnitOfPower.WATT, - device_class=SensorDeviceClass.ENERGY, + device_class=SensorDeviceClass.POWER, ), SensorEntityDescription( key="pvElec", @@ -376,7 +374,7 @@ def add_years(d, years): name="totalLoadPower", icon="mdi:solar-panel", native_unit_of_measurement=UnitOfPower.WATT, - device_class=SensorDeviceClass.ENERGY, + device_class=SensorDeviceClass.POWER, ), SensorEntityDescription( key="totalPvgenPower", @@ -395,7 +393,7 @@ def add_years(d, years): name="solarLoadPower", icon="mdi:solar-power", native_unit_of_measurement=UnitOfPower.WATT, - device_class=SensorDeviceClass.ENERGY, + device_class=SensorDeviceClass.POWER, ), SensorEntityDescription( key="homeLoadPower", @@ -724,7 +722,7 @@ async def async_update(self): previousChartYear = add_years(today, -1).strftime('%Y') nextChartYear = add_years(today, 1).strftime('%Y') chartYear = today.strftime('%Y') - epochmilliseconds = round(int((datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1)).total_seconds() * 1000)) + epochmilliseconds = int(dt.utcnow().timestamp() * 1000) elecDevicesn = deviceSnArr if self.sensors == "h1" else "" url4 = f"{self._provider.getBaseUrl()}/monitor/site/getPlantDetailChart2?plantuid={plantuid}&chartDateType=1&energyType=0&clientDate={clientDate}&deviceSnArr={deviceSnArr}&chartCountType=2&previousChartDay={previousChartDay}&nextChartDay={nextChartDay}&chartDay={chartDay}&previousChartMonth={previousChartMonth}&nextChartMonth={nextChartMonth}&chartMonth={chartMonth}&previousChartYear={previousChartYear}&nextChartYear={nextChartYear}&chartYear={chartYear}&elecDevicesn={elecDevicesn}&_={epochmilliseconds}" # _LOGGER.error(f"PlantCharts URL: {url4}") @@ -866,11 +864,11 @@ async def async_update(self): self._data = plantDetails # Error logging - except aiohttp.ClientError: - _LOGGER.error("Cannot poll eSolar using url: %s") + except aiohttp.ClientError as err: + _LOGGER.error("Cannot poll eSolar using url: %s", err) return - except asyncio.TimeoutError: - _LOGGER.error("Timeout error occurred while polling eSolar using url: %s") + except asyncio.TimeoutError as err: + _LOGGER.error("Timeout error occurred while polling eSolar using url: %s", err) return except Exception as err: _LOGGER.error("Unknown error occurred while polling eSolar: %s", err) @@ -927,7 +925,7 @@ def __init__(self, description: SensorEntityDescription, data, sensors, plant_id self._dev_id = {} @property - def state(self): + def native_value(self): """Return the state of the sensor. (total/current power consumption/production or total gas used)""" return self._state From c66fd02a01bc9804f84e2abb1c5e9aec6b5cc409 Mon Sep 17 00:00:00 2001 From: Martin Klemm Date: Wed, 1 Apr 2026 15:27:34 +0200 Subject: [PATCH 2/2] version update --- custom_components/saj_esolar/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/saj_esolar/manifest.json b/custom_components/saj_esolar/manifest.json index df0f98f..9418e4a 100644 --- a/custom_components/saj_esolar/manifest.json +++ b/custom_components/saj_esolar/manifest.json @@ -1,7 +1,7 @@ { "domain": "saj_esolar", "name": "SAJ eSolar", - "version": "1.5.7", + "version": "1.5.8", "requirements": [], "dependencies": [], "issue_tracker": "https://github.com/djansen1987/SAJeSolar/issues",