diff --git a/custom_components/chargeamps/__init__.py b/custom_components/chargeamps/__init__.py index 098ea7c..e931bef 100644 --- a/custom_components/chargeamps/__init__.py +++ b/custom_components/chargeamps/__init__.py @@ -16,6 +16,7 @@ ChargePointConnector, ChargePointConnectorSettings, ChargePointConnectorStatus, + ChargePointStatus, StartAuth, ) from chargeamps.external import ChargeAmpsExternalClient @@ -184,6 +185,9 @@ def get_chargepoint_total_energy(self, charge_point_id) -> float: def get_chargepoint_info(self, charge_point_id) -> ChargePoint: return self.hass.data[DOMAIN_DATA]["chargepoint_info"].get(charge_point_id) + def get_chargepoint_status(self, charge_point_id) -> ChargePointStatus: + return self.hass.data[DOMAIN_DATA]["chargepoint_status"].get(charge_point_id) + def get_chargepoint_settings(self, charge_point_id): return self.hass.data[DOMAIN_DATA]["chargepoint_settings"].get(charge_point_id) diff --git a/custom_components/chargeamps/const.py b/custom_components/chargeamps/const.py index 3df6201..268d97e 100644 --- a/custom_components/chargeamps/const.py +++ b/custom_components/chargeamps/const.py @@ -30,3 +30,6 @@ # Overall scan interval SCAN_INTERVAL = timedelta(seconds=10) + +# Chargepoint online status +CHARGEPOINT_ONLINE = "Online" diff --git a/custom_components/chargeamps/sensor.py b/custom_components/chargeamps/sensor.py index dfcdc1b..d2eb340 100644 --- a/custom_components/chargeamps/sensor.py +++ b/custom_components/chargeamps/sensor.py @@ -7,10 +7,10 @@ SensorEntity, SensorStateClass, ) -from homeassistant.const import UnitOfEnergy, UnitOfPower +from homeassistant.const import UnitOfEnergy, UnitOfPower, STATE_UNAVAILABLE from . import ChargeampsEntity -from .const import DOMAIN_DATA, SCAN_INTERVAL # noqa +from .const import DOMAIN_DATA, SCAN_INTERVAL, CHARGEPOINT_ONLINE # noqa _LOGGER = logging.getLogger(__name__) @@ -82,12 +82,16 @@ async def async_update(self): self.charge_point_id, self.connector_id, ) + cp_status = self.handler.get_chargepoint_status(self.charge_point_id) status = self.handler.get_connector_status( self.charge_point_id, self.connector_id ) if status is None: return - self._state = status.status + if cp_status.status != CHARGEPOINT_ONLINE: + self._state = STATE_UNAVAILABLE + else: + self._state = status.status self._attributes["total_consumption_kwh"] = round( status.total_consumption_kwh, 3 )