From b17766737ce10a68eb3f8f43ad5b3d706b73685f Mon Sep 17 00:00:00 2001 From: Nathan Marlor Date: Mon, 31 Oct 2022 10:05:13 +0000 Subject: [PATCH] Added disabled charge switch --- .../foxess_em/battery/battery_controller.py | 9 +++++++++ custom_components/foxess_em/charge/charge_service.py | 4 ++++ custom_components/foxess_em/const.py | 2 +- custom_components/foxess_em/switch.py | 7 +++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/custom_components/foxess_em/battery/battery_controller.py b/custom_components/foxess_em/battery/battery_controller.py index 5b51248..1e85407 100755 --- a/custom_components/foxess_em/battery/battery_controller.py +++ b/custom_components/foxess_em/battery/battery_controller.py @@ -51,6 +51,7 @@ def __init__( self._last_update = None self._boost = False self._full = False + self._disable = False # Refresh on SoC change battery_refresh = async_track_state_change( @@ -184,3 +185,11 @@ def set_full(self, status: bool) -> None: def full_status(self) -> bool: """Full status""" return self._full + + def set_disable(self, status: bool) -> None: + """Set disable on/off""" + self._disable = status + + def disable_status(self) -> bool: + """Disable status""" + return self._disable diff --git a/custom_components/foxess_em/charge/charge_service.py b/custom_components/foxess_em/charge/charge_service.py index a50d080..c284abc 100755 --- a/custom_components/foxess_em/charge/charge_service.py +++ b/custom_components/foxess_em/charge/charge_service.py @@ -78,6 +78,10 @@ def __init__( async def _eco_start_setup(self, *args) -> None: # pylint: disable=unused-argument """Set target SoC""" + if self._battery_controller.disable_status() is True: + _LOGGER.info("Skipping setup of charging schedule due to disabled status") + return + _LOGGER.debug("Calculating optimal battery SoC") await self._forecast_controller.async_refresh() diff --git a/custom_components/foxess_em/const.py b/custom_components/foxess_em/const.py index 489e46b..63e1ff7 100755 --- a/custom_components/foxess_em/const.py +++ b/custom_components/foxess_em/const.py @@ -20,7 +20,7 @@ SOLCAST_API_SITE = "site" SOLCAST_API_KEY = "key" SOLCAST_SCAN_INTERVAL = "scan_interval" -# SOLCAST_URL = "https://8b382699-2afc-4114-befe-d26e2e0381a2.mock.pstmn.io" +# SOLCAST_URL = "https://19a8e676-7094-43d3-a2d3-e1e7304f9eda.mock.pstmn.io" SOLCAST_URL = "https://api.solcast.com.au" FOX_USERNAME = "fox_username" FOX_PASSWORD = "fox_password" diff --git a/custom_components/foxess_em/switch.py b/custom_components/foxess_em/switch.py index c6ea2db..eeef5d4 100755 --- a/custom_components/foxess_em/switch.py +++ b/custom_components/foxess_em/switch.py @@ -26,6 +26,13 @@ is_on="full_status", switch="set_full", ), + "disable": SwitchDescription( + key="disable", + name="Disable Auto Charge", + icon="mdi:sync-off", + is_on="disable_status", + switch="set_disable", + ), }