Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
magnuselden authored and magnuselden committed Dec 12, 2023
1 parent 24ff497 commit b117fbc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import logging
import time
from typing import TYPE_CHECKING, Tuple

from peaqevcore.common.models.observer_types import ObserverTypes
Expand All @@ -11,7 +10,7 @@

if TYPE_CHECKING:
from custom_components.peaqev.peaqservice.hub.hub import HomeAssistantHub

from peaqevcore.common.wait_timer import WaitTimer
from peaqevcore.models.chargecontroller_states import ChargeControllerStates

from custom_components.peaqev.peaqservice.chargecontroller.chargecontroller_helpers import \
Expand All @@ -29,7 +28,6 @@ def __init__(
self, hub: HomeAssistantHub, charger_states: dict, charger_type: ChargerType
):
self._aux_running_grace_timer = WaitTimer(timeout=300, init_now=True)
self._init_time = time.time()
super().__init__(hub, charger_states, charger_type)

@property
Expand Down Expand Up @@ -106,7 +104,7 @@ async def async_get_status_connected(

async def _aux_check_running_charger_mismatch(self, status_type: ChargeControllerStates) -> None:
if self._aux_running_grace_timer.is_timeout():
_LOGGER.warning(f"Charger seems to be running without Peaqev controlling it. Attempting aux stop. If you wish to charge without Peaqev you need to disable it on the switch. {self._aux_running_grace_timer.value}, {self._aux_running_grace_timer.timeout}, {self._init_time}")
_LOGGER.warning(f"Charger seems to be running without Peaqev controlling it. Attempting aux stop. If you wish to charge without Peaqev you need to disable it on the switch.")
await self.hub.observer.async_broadcast(ObserverTypes.KillswitchDead)
self._aux_running_grace_timer.reset()
elif status_type in [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, controller):
self.model = ChargerModel()
self.helpers = ChargerHelpers(self)
self.controller.hub.observer.add(ObserverTypes.PowerCanaryDead, self.async_pause_charger)
self.controller.hub.observer.add(ObserverTypes.KillswitchDead, self.async_pause_charger)
self.controller.hub.observer.add(ObserverTypes.KillswitchDead, self.async_terminate_charger)
self.controller.hub.observer.add(ObserverTypes.CarConnected, self.async_reset_session)
self.controller.hub.observer.add(ObserverTypes.ProcessCharger, self.async_charge)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ async def async_set_status(self) -> None:
except Exception as e:
_LOGGER.debug(f"Error in async_set_status2: {e}")

@abstractmethod
async def _aux_check_running_charger_mismatch(self, status_type: ChargeControllerStates) -> None:
pass

async def async_set_status_type(self, status_type: ChargeControllerStates) -> None:
try:
if isinstance(status_type, ChargeControllerStates):
Expand All @@ -132,6 +136,7 @@ async def async_set_status_type(self, status_type: ChargeControllerStates) -> No
self.model.status_type = status_type
if self.model.charger_type is not ChargerType.NoCharger: #todo: strategy should handle this
await self.hub.observer.async_broadcast(ObserverTypes.ProcessCharger)
await self._aux_check_running_charger_mismatch(status_type)
except Exception as e:
_LOGGER.debug(f"Error in async_set_status_type: {e}")

Expand Down

0 comments on commit b117fbc

Please sign in to comment.