Skip to content

Commit

Permalink
Admin keepalive and release control buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
thdfw committed Dec 30, 2024
1 parent 52dec04 commit acceb24
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 2 deletions.
6 changes: 5 additions & 1 deletion gw_spaceheat/actors/scada.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
from enums import MainAutoState, TopState
from named_types import (DispatchContractGoDormant, DispatchContractGoLive, EnergyInstruction,
FsmEvent, GoDormant, LayoutLite, PicoMissing, ScadaParams,
SendLayout, WakeUp)
SendLayout, WakeUp, AdminKeepAlive, AdminReleaseControl)

ScadaMessageDecoder = create_message_model(
"ScadaMessageDecoder",
Expand Down Expand Up @@ -465,6 +465,10 @@ def _derived_process_message(self, message: Message):
path_dbg = 0
from_node = self._layout.node(message.Header.Src, None)
match message.Payload:
case AdminKeepAlive():
self._renew_admin_timeout()
case AdminReleaseControl():
self.admin_times_out()
case RemainingElec():
try:
self.get_communicator(H0N.atomic_ally).process_message(message)
Expand Down
12 changes: 11 additions & 1 deletion gw_spaceheat/admin/watch/clients/relay_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from admin.watch.clients.admin_client import AdminSubClient
from admin.watch.clients.constrained_mqtt_client import MessageReceivedCallback
from admin.watch.clients.constrained_mqtt_client import StateChangeCallback
from named_types import FsmEvent, LayoutLite
from named_types import FsmEvent, LayoutLite, AdminKeepAlive, AdminReleaseControl

module_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -301,3 +301,13 @@ def _send_set_command(
)
)

def send_keepalive(self) -> None:
self._admin_client.publish(
AdminKeepAlive()
)

def send_release_control(self) -> None:
self._admin_client.publish(
AdminReleaseControl()
)

49 changes: 49 additions & 0 deletions gw_spaceheat/admin/watch/watchex/relays2.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,52 @@ def on_button_pressed(self):
)


class KeepAliveButton(Button):
def __init__(
self,
logger: logging.Logger = module_logger,
**kwargs
) -> None:
super().__init__(
"Keep alive",
variant="primary",
id="keepalive_button",
**kwargs
)
self.logger = logger

class Pressed(Message):
...

def on_button_pressed(self) -> None:
self.post_message(
KeepAliveButton.Pressed()
)


class ReleaseControlButton(Button):
def __init__(
self,
logger: logging.Logger = module_logger,
**kwargs
) -> None:
super().__init__(
"Release control",
variant="primary",
id="release_control_button",
**kwargs
)
self.logger = logger

class Pressed(Message):
...

def on_button_pressed(self) -> None:
self.post_message(
ReleaseControlButton.Pressed()
)


class Relays2(Relays):
BINDINGS = [
("n", "toggle_relay", "Toggle selected relay"),
Expand Down Expand Up @@ -172,6 +218,9 @@ def compose(self) -> ComposeResult:
config=Relays2.curr_config,
)
yield DataTable(id="message_table", classes="undisplayed")
with Horizontal():
yield KeepAliveButton()
yield ReleaseControlButton()

def on_mount(self) -> None:
data_table = self.query_one("#relays_table", DataTable)
Expand Down
8 changes: 8 additions & 0 deletions gw_spaceheat/admin/watch/watchex/watchex_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from admin.watch.watchex.relays2 import Relays2
from admin.watch.watchex.relays2 import RelayToggleButton
from admin.watch.widgets.relay2 import RelayControlButtons
from admin.watch.watchex.relays2 import KeepAliveButton
from admin.watch.watchex.relays2 import ReleaseControlButton

logger = logging.getLogger(__name__)
logger.addHandler(TextualHandler())
Expand Down Expand Up @@ -85,6 +87,12 @@ def on_relay_toggle_button_pressed(self, message: RelayToggleButton.Pressed):
RelayEnergized.energized if message.energize else RelayEnergized.deenergized
)

def on_keep_alive_button_pressed(self, _: KeepAliveButton.Pressed):
self._relay_client.send_keepalive()

def on_release_control_button_pressed(self, _: ReleaseControlButton.Pressed):
self._relay_client.send_release_control()

def action_toggle_dark(self) -> None:
self.theme = (
"textual-dark" if "light" in self.theme else "textual-light"
Expand Down
4 changes: 4 additions & 0 deletions gw_spaceheat/named_types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from named_types.fsm_event import FsmEvent
from named_types.go_dormant import GoDormant
from named_types.ha1_params import Ha1Params
from named_types.admin_keepalive import AdminKeepAlive
from named_types.admin_release_control import AdminReleaseControl
from named_types.latest_price import LatestPrice
from named_types.layout_lite import LayoutLite
from named_types.pico_missing import PicoMissing
Expand All @@ -27,6 +29,8 @@
"FsmEvent",
"GoDormant",
"Ha1Params",
"AdminKeepAlive",
"AdminReleaseControl",
"LatestPrice",
"LayoutLite",
"PicoMissing",
Expand Down
7 changes: 7 additions & 0 deletions gw_spaceheat/named_types/admin_keepalive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from typing import List, Literal
from pydantic import BaseModel, field_validator, model_validator


class AdminKeepAlive(BaseModel):
TypeName: Literal["admin.keepalive"] = "admin.keepalive"
Version: Literal["001"] = "001"
7 changes: 7 additions & 0 deletions gw_spaceheat/named_types/admin_release_control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from typing import List, Literal
from pydantic import BaseModel, field_validator, model_validator


class AdminReleaseControl(BaseModel):
TypeName: Literal["admin.release.control"] = "admin.release.control"
Version: Literal["001"] = "001"

0 comments on commit acceb24

Please sign in to comment.