From 2d14fab2a3d13ce4e531644604f523fbc4434dbc Mon Sep 17 00:00:00 2001 From: Jessica Millar Date: Sat, 4 Jan 2025 10:56:30 -0500 Subject: [PATCH] onpeak-backup node sends messages to relays correctly --- gw_spaceheat/actors/home_alone.py | 37 +++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/gw_spaceheat/actors/home_alone.py b/gw_spaceheat/actors/home_alone.py index 29838fa3..9577403a 100644 --- a/gw_spaceheat/actors/home_alone.py +++ b/gw_spaceheat/actors/home_alone.py @@ -269,10 +269,12 @@ def trigger_house_cold_onpeak_event(self) -> None: - reports top state change """ - if not self.house_is_cold_onpeak(): - self.log("Not triggering HouseColdOnpeak top event - house is not cold onpeak!") - if not self.top_state == HomeAloneTopState.Normal: - self.log("Not triggering HouseColdOnpeak top event - not in top state Normal!") + # if not self.house_is_cold_onpeak(): + # self.log("Not triggering HouseColdOnpeak top event - house is not cold onpeak!") + # return + # if not self.top_state == HomeAloneTopState.Normal: + # self.log("Not triggering HouseColdOnpeak top event - not in top state Normal!") + # return # implement the change in command tree. Boss: h.n -> h.onpeak-backup self.set_onpeak_backup_command_tree() # and let the normal homealone know its dormant until further notice @@ -481,7 +483,10 @@ def leaving_onpeak_backup_actuator_actions(self) -> None: SendTimeUnixMs=int(time.time() * 1000), TriggerId=str(uuid.uuid4()), ) - self._send_to(self.hp_failsafe_relay, event) + self.services.send(Message(Src=self.onpeak_backup_node.name, + Dst=self.hp_failsafe_relay.name, + Payload=event)) + self.log( f"{self.onpeak_backup_node.handle} sending SwitchToTankAquastat to Hp Failsafe {H0N.hp_failsafe_relay}" ) @@ -497,7 +502,10 @@ def leaving_onpeak_backup_actuator_actions(self) -> None: SendTimeUnixMs=int(time.time() * 1000), TriggerId=str(uuid.uuid4()), ) - self._send_to(self.aquastat_control_relay, event) + self.services.send(Message(Src=self.onpeak_backup_node.name, + Dst=self.hp_failsafe_relay.name, + Payload=event)) + self.log( f"{self.node.handle} sending SwitchToScada to Boiler Ctrl {H0N.aquastat_ctrl_relay}" ) @@ -513,6 +521,8 @@ def onpeak_backup_actuator_actions(self) -> None: - turn on heat pump Expects set_onpeak_backup_command_tree already called, with self.onpeak_backup_node as boss + WEAKNESS: SENDS MESSAGES TO RELAY ONLY VIA INTERNAL python QUEUE. WILL FAIL + IF HOME ALONE IS PUT IN A DIFFERENT PROCESS THAN THE ACTUATORS """ if self.settings.oil_boiler_for_onpeak_backup: @@ -528,7 +538,14 @@ def onpeak_backup_actuator_actions(self) -> None: SendTimeUnixMs=int(time.time() * 1000), TriggerId=str(uuid.uuid4()), ) - self._send_to(self.hp_failsafe_relay, event) + # CANNOT USE _send_to because that sends a message from the actor's node + # and this message needs to come from onpeak_backup_node + # NOTE: THIS ASSUMES THE RELAY IS IN THE SAME CODEBASE AS + # HOMEALONE. + self.services.send(Message(Src=self.onpeak_backup_node.name, + Dst=self.hp_failsafe_relay.name, + Payload=event)) + self.log( f"{self.onpeak_backup_node.handle} sending SwitchToTankAquastat to Hp Failsafe {H0N.hp_failsafe_relay}" ) @@ -544,9 +561,11 @@ def onpeak_backup_actuator_actions(self) -> None: SendTimeUnixMs=int(time.time() * 1000), TriggerId=str(uuid.uuid4()), ) - self._send_to(self.aquastat_control_relay, event) + self.services.send(Message(Src=self.onpeak_backup_node.name, + Dst=self.hp_failsafe_relay.name, + Payload=event)) self.log( - f"{self.node.handle} sending SwitchToScada to Boiler Ctrl {H0N.aquastat_ctrl_relay}" + f"{self.onpeak_backup_node.handle} sending SwitchToScada to Boiler Ctrl {H0N.aquastat_ctrl_relay}" ) except ValidationError as e: self.log(f"Tried to switch AquastatCtrl relay to Boiler but didn't have the rights: {e}")