Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion custom_components/saj_esolar/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
24 changes: 11 additions & 13 deletions custom_components/saj_esolar/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from typing import Final

import aiohttp
import async_timeout
import voluptuous as vol

from homeassistant.components.sensor import (
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down