diff --git a/custom_components/peaqev/manifest.json b/custom_components/peaqev/manifest.json index 79aabe07..49a3f125 100644 --- a/custom_components/peaqev/manifest.json +++ b/custom_components/peaqev/manifest.json @@ -24,7 +24,7 @@ "iot_class": "calculated", "issue_tracker": "https://github.com/elden1337/hass-peaq/issues", "requirements": [ - "peaqevcore==19.10.10" + "peaqevcore==19.10.12" ], "version": "3.6.1b0" } diff --git a/custom_components/peaqev/peaqservice/chargecontroller/chargecontroller.py b/custom_components/peaqev/peaqservice/chargecontroller/chargecontroller.py index cba138d3..b1ed4aa1 100644 --- a/custom_components/peaqev/peaqservice/chargecontroller/chargecontroller.py +++ b/custom_components/peaqev/peaqservice/chargecontroller/chargecontroller.py @@ -21,9 +21,10 @@ _LOGGER = logging.getLogger(__name__) + class ChargeController(IChargeController): def __init__( - self, hub: HomeAssistantHub, charger_states: dict, charger_type: ChargerType + self, hub: HomeAssistantHub, charger_states: dict, charger_type: ChargerType ): self._aux_running_grace_timer = WaitTimer(timeout=300, init_now=True) super().__init__(hub, charger_states, charger_type) @@ -48,7 +49,11 @@ def _check_initialized(self) -> bool: if float_state > 0: return self._do_initialize() except Exception as e: - _LOGGER.error('Could not convert state to float: %s', e) + _LOGGER.error( + 'Could not convert state to float for sensor (%s). Exception: %s', + self.hub.options.powersensor, + e + ) return False return False @@ -70,12 +75,12 @@ async def async_get_energy_and_peak(self) -> Tuple[float, float]: async def async_get_status_charging(self) -> ChargeControllerStates: if any([not self.hub.power.power_canary.alive, self.hub.events.aux_stop, all( - [ - await self.async_above_stopthreshold(), - self.hub.sensors.totalhourlyenergy.value > 0, - not await self.hub.async_free_charge(), - ] - )]): + [ + await self.async_above_stopthreshold(), + self.hub.sensors.totalhourlyenergy.value > 0, + not await self.hub.async_free_charge(), + ] + )]): return ChargeControllerStates.Stop return ChargeControllerStates.Start diff --git a/custom_components/peaqev/peaqservice/hub/hub.py b/custom_components/peaqev/peaqservice/hub/hub.py index f77ef2ba..014012f6 100644 --- a/custom_components/peaqev/peaqservice/hub/hub.py +++ b/custom_components/peaqev/peaqservice/hub/hub.py @@ -174,6 +174,9 @@ async def async_update_prices(self, prices: list) -> None: async def async_is_caution_hour(self) -> bool: return str(datetime.now().hour) in [str(h) for h in self.hours.caution_hours] + def _check_max_min_total_charge(self, ret: dict) -> None: + pass + async def async_request_sensor_data(self, *args) -> dict | any: ret = {} if not self.is_initialized: @@ -192,10 +195,7 @@ async def async_request_sensor_data(self, *args) -> dict | any: return val return ret - def _check_max_min_total_charge(self, ret: dict) -> None: - pass - - def _request_sensor_lookup(self) -> dict: + def _request_sensor_lookup(self) -> dict[LookupKeys, Callable]: """Proxies the request to the correct sensor.""" return { LookupKeys.CHARGER_DONE: partial(getattr, self.sensors.charger_done, 'value'), @@ -251,12 +251,12 @@ def _request_sensor_lookup(self) -> dict: def now_is_non_hour(self) -> bool: now = datetime.now().replace(minute=0, second=0, microsecond=0) - non_hours = self._request_sensor_lookup().get(LookupKeys.NON_HOURS, []) + non_hours = self._request_sensor_lookup().get(LookupKeys.NON_HOURS, [])[0]() return now in non_hours def now_is_caution_hour(self) -> bool: now = datetime.now().replace(minute=0, second=0, microsecond=0) - caution_hours = self._request_sensor_lookup().get(LookupKeys.DYNAMIC_CAUTION_HOURS, {}) + caution_hours = self._request_sensor_lookup().get(LookupKeys.DYNAMIC_CAUTION_HOURS, {})[0]() return now in caution_hours.keys() async def async_free_charge(self) -> bool: diff --git a/custom_components/peaqev/peaqservice/hub/price_aware_hub.py b/custom_components/peaqev/peaqservice/hub/price_aware_hub.py index dd3cdc66..db37ce26 100644 --- a/custom_components/peaqev/peaqservice/hub/price_aware_hub.py +++ b/custom_components/peaqev/peaqservice/hub/price_aware_hub.py @@ -27,7 +27,7 @@ def scheduler_options_handler(self) -> SchedulerOptionsHandler: @property def current_peak_dynamic(self): """Dynamically calculated peak to adhere to caution-hours""" - dynamic_caution_hours = self._request_sensor_lookup().get(LookupKeys.DYNAMIC_CAUTION_HOURS, {}) + dynamic_caution_hours: dict = self._request_sensor_lookup().get(LookupKeys.DYNAMIC_CAUTION_HOURS, {})() if len(dynamic_caution_hours) > 0: if self.now_is_caution_hour() and not getattr(self.hours.timer, 'is_override', False): return self.sensors.current_peak.observed_peak * dynamic_caution_hours.get(datetime.now().replace(minute=0, second=0, microsecond=0), 1) diff --git a/custom_components/peaqev/peaqservice/hub/servicecalls.py b/custom_components/peaqev/peaqservice/hub/servicecalls.py index bd0a142f..b505148d 100644 --- a/custom_components/peaqev/peaqservice/hub/servicecalls.py +++ b/custom_components/peaqev/peaqservice/hub/servicecalls.py @@ -3,6 +3,7 @@ from typing import TYPE_CHECKING from peaqevcore.common.models.observer_types import ObserverTypes +from peaqevcore.services.scheduler.update_scheduler_dto import UpdateSchedulerDTO if TYPE_CHECKING: from custom_components.peaqev.peaqservice.hub.hub import HomeAssistantHub @@ -63,7 +64,15 @@ async def async_call_schedule_needed_charge( await self.hub.hours.scheduler.async_create_schedule( charge_amount, dep_time, start_time, override_settings ) - await self.hub.hours.scheduler.async_update_facade() + dto = UpdateSchedulerDTO( + moving_avg24=self.hub.sensors.powersensormovingaverage24.value, + peak=self.hub.current_peak_dynamic, + charged_amount=self.hub.chargecontroller.session.session_energy, + prices=self.hub.hours.prices, + prices_tomorrow=self.hub.hours.prices_tomorrow, + chargecontroller_state = self.hub.chargecontroller.status_type + ) + await self.hub.hours.scheduler.async_update_facade(dto) await self.hub.observer.async_broadcast(ObserverTypes.SchedulerCreated) async def async_call_scheduler_cancel(self): diff --git a/custom_components/peaqev/peaqservice/hub/state_changes/istate_changes.py b/custom_components/peaqev/peaqservice/hub/state_changes/istate_changes.py index 3a481972..40c67c69 100644 --- a/custom_components/peaqev/peaqservice/hub/state_changes/istate_changes.py +++ b/custom_components/peaqev/peaqservice/hub/state_changes/istate_changes.py @@ -73,7 +73,8 @@ async def async_update_session_parameters(self, update_session: bool) -> None: peak=self.hub.current_peak_dynamic, charged_amount=self.hub.chargecontroller.session.session_energy, prices=self.hub.hours.prices, - prices_tomorrow=self.hub.hours.prices_tomorrow + prices_tomorrow=self.hub.hours.prices_tomorrow, + chargecontroller_state=self.hub.chargecontroller.status_type ) await self.hub.hours.scheduler.async_update_facade(dto) except Exception as e: