Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

admin: relays in a table #289

Merged
merged 19 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0bf1ba0
WIP: add 'watchex' for experimental watch features, and first pass of…
anschweitzer Dec 18, 2024
bddd9ae
WIP: admin - watchex - first pass buttons added
anschweitzer Dec 21, 2024
a80ae41
admin: tdemo - textual actions/bindings/focus demo
anschweitzer Dec 22, 2024
491426a
admin: RelayButton titles
anschweitzer Dec 22, 2024
555425c
admin - RelayControlButtons: add bindings and focus control
anschweitzer Dec 23, 2024
ba05827
admin - RelayControlButtons - fix actions
anschweitzer Dec 23, 2024
01c357c
admin - watchex: Added bindings and generally cleaned up UI interaction
anschweitzer Dec 23, 2024
3511dbc
admin - watchex: fix theme change
anschweitzer Dec 23, 2024
ad0c530
admin - watchex: disable relay state colors by default
anschweitzer Dec 23, 2024
1b4e24d
Merge branch 'main' into as/relay-table
anschweitzer Dec 25, 2024
5be84be
WIP toggle button: NOTE - button text broken after scrolling
anschweitzer Dec 26, 2024
7bf693f
Merge branch 'main' into as/relay-table
anschweitzer Dec 29, 2024
06224ee
Remove logging tests that are not in proactor
anschweitzer Dec 29, 2024
8ec4502
Remove logging tests that are now in proactor and would need to be up…
anschweitzer Dec 29, 2024
a51849d
admin: fix toggle button text
anschweitzer Dec 29, 2024
d8c323c
admin: toggle button improvement: Title of current relay for border b…
anschweitzer Dec 29, 2024
c41a6ea
Make toggle button default
anschweitzer Dec 29, 2024
7f0429d
Merge branch 'as/relay-table' of https://github.com/thegridelectric/g…
anschweitzer Dec 29, 2024
c150ded
admin - watchex - hide binding for coloring state string
anschweitzer Dec 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 63 additions & 24 deletions gw_spaceheat/admin/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import rich
import typer

from gwproactor.command_line_utils import get_settings, print_settings
from gwproactor.command_line_utils import print_settings

from admin.tdemo.cli import app as tdemo_cli
from admin.settings import AdminClientSettings
from admin.watch.relay_app import RelaysApp
from admin.watch.watchex.watchex_app import WatchExApp

app = typer.Typer(
no_args_is_help=True,
Expand All @@ -27,26 +28,12 @@ class RelayState(StrEnum):
open = "0"
closed = "1"


@app.command()
def watch(
def watch_settings(
target: str = "",
env_file: str = ".env",
verbose: Annotated[
int,
typer.Option(
"--verbose", "-v", count=True
)
] = 0,
paho_verbose: Annotated[
int,
typer.Option(
"--paho-verbose", count=True
)
] = 0

) -> None:
"""Watch and set relays. """
verbose: int = 0,
paho_verbose: int = 0
) -> AdminClientSettings:
# https://github.com/koxudaxi/pydantic-pycharm-plugin/issues/1013
# noinspection PyArgumentList
settings = AdminClientSettings(
Expand All @@ -68,21 +55,73 @@ def watch(
else:
paho_verbosity = logging.DEBUG
settings.paho_verbosity = paho_verbosity
return settings

@app.command()
def watch(
target: str = "",
env_file: str = ".env",
verbose: Annotated[
int,
typer.Option(
"--verbose", "-v", count=True
)
] = 0,
paho_verbose: Annotated[
int,
typer.Option(
"--paho-verbose", count=True
)
] = 0
) -> None:
"""Watch and set relays."""
settings = watch_settings(target, env_file, verbose, paho_verbose)
rich.print(settings)
watch_app = RelaysApp(settings=settings)
watch_app.run()

@app.command()
def watchex(
target: str = "",
env_file: str = ".env",
verbose: Annotated[
int,
typer.Option(
"--verbose", "-v", count=True
)
] = 0,
paho_verbose: Annotated[
int,
typer.Option(
"--paho-verbose", count=True
)
] = 0
) -> None:
"""Watch and set relays with experimental features"""
settings = watch_settings(target, env_file, verbose, paho_verbose)
rich.print(settings)
watch_app = WatchExApp(settings=settings)
watch_app.run()

@app.command()
def config(
target: str = "",
env_file: str = ".env",
verbose: Annotated[
int,
typer.Option(
"--verbose", "-v", count=True
)
] = 0,
paho_verbose: Annotated[
int,
typer.Option(
"--paho-verbose", count=True
)
] = 0
) -> None:
"""Show admin settings."""
settings = get_settings(settings_type=AdminClientSettings, env_file=env_file)
if target:
settings.target_gnode = target
elif not settings.target_gnode:
settings.target_gnode = DEFAULT_TARGET
settings = watch_settings(target, env_file, verbose, paho_verbose)
print_settings(settings=settings, env_file=env_file)


Expand Down
46 changes: 46 additions & 0 deletions gw_spaceheat/admin/tdemo/actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from textual.app import App, ComposeResult
from textual.widgets import Button
from textual.widgets import Footer
from textual.widgets import Static

TEXT = """
[b]Set your background[/b]
[@click=set_background('cyan')]Cyan[/]
[@click=set_background('magenta')]Magenta[/]
[@click=set_background('yellow')]Yellow[/]
"""


class ColorSwitcher(Static, can_focus=True):
BINDINGS = [
("o", "set_background('olive')", "olive"),
("w", "set_background('ansi_white')", "ansi_white"),
("s", "set_background('silver')", "silver"),
]
def action_set_background(self, color: str) -> None:
self.styles.background = color


class ActionsApp(App):
CSS_PATH = "actions05.tcss"
BINDINGS = [
("q", "quit"),
("ctrl+c", "quit"),
("r", "set_background('red')", "Red"),
("g", "set_background('green')", "Green"),
("b", "set_background('blue')", "Blue"),
]

def compose(self) -> ComposeResult:
yield ColorSwitcher(TEXT)
yield ColorSwitcher(TEXT)
yield Button("foo")
yield Footer()

def action_set_background(self, color: str) -> None:
self.screen.styles.background = color


if __name__ == "__main__":
app = ActionsApp()
app.run()
20 changes: 20 additions & 0 deletions gw_spaceheat/admin/tdemo/actions05.tcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Screen {
layout: grid;
grid-size: 1;
grid-gutter: 2 4;
grid-rows: 1fr;
}

ColorSwitcher {
height: 100%;
margin: 2 4;
border: solid blue;

&:focus {
background: $primary;
color: $text;
text-style: bold;
outline-left: thick $accent;
}
}

7 changes: 7 additions & 0 deletions gw_spaceheat/admin/tdemo/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import typer

from admin.tdemo.actions import ActionsApp
from admin.tdemo.stopwatch import StopwatchApp
from admin.tdemo.switch import SwitchApp

Expand All @@ -23,6 +24,12 @@ def switch():
switch_app = SwitchApp()
switch_app.run()

@app.command()
def actions():
"""Run textual actions demo"""
actions_app = ActionsApp()
actions_app.run()


@app.callback()
def _main() -> None: ...
Expand Down
2 changes: 0 additions & 2 deletions gw_spaceheat/admin/watch/relay_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import dotenv
from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.css.query import NoMatches
from textual.logging import TextualHandler
from textual.reactive import reactive
from textual.reactive import Reactive
Expand All @@ -17,7 +16,6 @@
from admin.watch.widgets.relay1 import Relay1
from admin.watch.widgets.relay2 import Relay2
from admin.watch.widgets.relay2 import RelayControlButtons
from admin.watch.widgets.relays import Relay
from admin.watch.widgets.relays import Relays

logger = logging.getLogger(__name__)
Expand Down
Empty file.
Loading
Loading