Skip to content

Commit

Permalink
Merge branch 'main' into jm/pump-reset
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamillar committed Dec 20, 2024
2 parents b93a614 + 10ce3a0 commit 5dd973c
Show file tree
Hide file tree
Showing 41 changed files with 2,291 additions and 886 deletions.
23 changes: 16 additions & 7 deletions gw_spaceheat/actors/api_flow_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ async def main(self):
except Exception as e:
try:
if not isinstance(e, asyncio.CancelledError):
self.services.logger.exception(e)
self.log(e)
self._send(
InternalShutdownMessage(
Src=self.name,
Expand Down Expand Up @@ -292,15 +292,17 @@ async def _handle_hall_params_post(self, request: Request) -> Response:
params = FlowHallParams(**json.loads(text))
except BaseException as e:
self._report_post_error(e, "malformed FlowHall parameters!")
return
self.log("Flow module params are malformed")
return Response()
if params.FlowNodeName != self._component.gt.FlowNodeName:
return
self.log("FlowNodeName is not correct")
return Response()
if self._component.cac.MakeModel != MakeModel.GRIDWORKS__PICOFLOWHALL:
raise Exception(
f"{self.name} has {self._component.cac.MakeModel}"
"but got FlowHallParams!"
)
self.log(f"{params.HwUid} PARAMS")
self.pico_state_log(f"{params.HwUid} PARAMS")
# temporary hack prior to installerapp - in case a pico gets installed
# and the hardware layout does not have its id yet
if self._component.gt.HwUid is None or self._component.gt.HwUid == params.HwUid:
Expand Down Expand Up @@ -329,15 +331,17 @@ async def _handle_reed_params_post(self, request: Request) -> Response:
params = FlowReedParams(**json.loads(text))
except BaseException as e:
self._report_post_error(e, "malformed tankmodule parameters!")
return
self.log("Flow module params are malformed")
return Response()
if params.FlowNodeName != self._component.gt.FlowNodeName:
return
self.log("FlowNodeName is not correct")
return Response()
if self._component.cac.MakeModel != MakeModel.GRIDWORKS__PICOFLOWREED:
raise Exception(
f"{self.name} has {self._component.cac.MakeModel}"
"but got FlowReedParams!"
)
self.log(f"{params.HwUid} PARAMS")
self.pico_state_log(f"{params.HwUid} PARAMS")
if self._component.gt.HwUid is None or self._component.gt.HwUid == params.HwUid:
if self._component.gt.HwUid is None:
self.hw_uid = params.HwUid
Expand Down Expand Up @@ -762,3 +766,8 @@ def pico_cycler(self) -> Optional[ShNode]:
if H0N.pico_cycler in self.layout.nodes:
return self.layout.nodes[H0N.pico_cycler]
return None

def pico_state_log(self, note: str) -> None:
log_str = f"[PicoRelated] {note}"
if self.settings.pico_cycler_state_logging:
self.services.logger.error(log_str)
27 changes: 9 additions & 18 deletions gw_spaceheat/actors/api_tank_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def __init__(
path="/" + self.params_path,
handler=self._handle_params_post,
)
self.log_data = False
self.pico_a_uid = self._component.gt.PicoAHwUid
self.pico_b_uid = self._component.gt.PicoBHwUid
# use the following for generate pico offline reports for triggering the pico cycler
Expand Down Expand Up @@ -150,9 +149,9 @@ async def _handle_params_post(self, request: Request) -> Response:
params = TankModuleParams(**json.loads(text))
except BaseException as e:
self._report_post_error(e, "malformed tankmodule parameters!")
return
return Response()
if params.ActorNodeName != self.name:
return
return Response()

if self.is_valid_pico_uid(params):
cfg = next(
Expand Down Expand Up @@ -186,7 +185,7 @@ async def _handle_params_post(self, request: Request) -> Response:
)
# TODO: send message to self so that writing to hardware layout isn't
# happening in IO loop
self.log(f"{self.name}-{params.PicoAB}, {params.HwUid} ")
self.pico_state_log(f"{self.name}-{params.PicoAB}, {params.HwUid} ")
return Response(text=new_params.model_dump_json())
else:
# A strange pico is identifying itself as our "a" tank
Expand Down Expand Up @@ -216,7 +215,7 @@ def _process_microvolts(self, data: MicroVolts) -> None:
elif data.HwUid == self.pico_b_uid:
self.last_heard_b = time.time()
else:
self.services.logger.error(
self.log(
f"{self.name}: Ignoring data from pico {data.HwUid} - not recognized!"
)
return
Expand Down Expand Up @@ -254,19 +253,6 @@ def _process_microvolts(self, data: MicroVolts) -> None:
)
self._send_to(self.pico_cycler, msg)
self._send_to(self.primary_scada, msg)
# self.services.logger.error("sending temperatures to scada")
if self.log_data:
combined = list(zip(data.AboutNodeNameList, data.MicroVoltsList))
combined.sort(key=lambda x: x[0])
data.AboutNodeNameList, data.MicroVoltsList = zip(*combined)
for i in range(len(data.MicroVoltsList)):
mv = data.MicroVoltsList[i]
try:
temp_f = self.simple_beta_for_pico(mv / 1e6, fahrenheit=True)
self.log(f"{data.AboutNodeNameList[i]}: {round(temp_f, 2)} F")
except Exception:
#TODO - raise problem??
self.log(f"{data.AboutNodeNameList[i]}: OPEN")

def process_message(self, message: Message) -> Result[bool, BaseException]:
match message.Payload:
Expand Down Expand Up @@ -368,3 +354,8 @@ def pico_cycler(self) -> Optional[ShNode]:
if H0N.pico_cycler in self.layout.nodes:
return self.layout.nodes[H0N.pico_cycler]
return None

def pico_state_log(self, note: str) -> None:
log_str = f"[PicoRelated] {note}"
if self.settings.pico_cycler_state_logging:
self.services.logger.error(log_str)
Loading

0 comments on commit 5dd973c

Please sign in to comment.