Skip to content

Commit

Permalink
Merge pull request kirei#50 from viiru-/show-chargepoint-unavailable-…
Browse files Browse the repository at this point in the history
…if-offline

Also consider chargepoint status in ChargeampsSensor
  • Loading branch information
jschlyter authored May 15, 2024
2 parents 4275382 + 952f2a8 commit 24212d3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions custom_components/chargeamps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
ChargePointConnector,
ChargePointConnectorSettings,
ChargePointConnectorStatus,
ChargePointStatus,
StartAuth,
)
from chargeamps.external import ChargeAmpsExternalClient
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions custom_components/chargeamps/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@

# Overall scan interval
SCAN_INTERVAL = timedelta(seconds=10)

# Chargepoint online status
CHARGEPOINT_ONLINE = "Online"
10 changes: 7 additions & 3 deletions custom_components/chargeamps/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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
)
Expand Down

0 comments on commit 24212d3

Please sign in to comment.