Skip to content

Commit

Permalink
splits the Status model
Browse files Browse the repository at this point in the history
creating a Config model that does noet contain the read-only part 'info'
as [per agreement](brianhealey#16 (comment)) in brianhealey#16 thread
  • Loading branch information
marc-portier committed Dec 29, 2022
1 parent 6702fb4 commit e67f5b1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pyamplipi/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from tabulate import tabulate
from textwrap import indent
import validators
from .models import Status, Info, Source, Zone, Group, Stream, Preset, Announcement
from .models import Status, Config, Info, Source, Zone, Group, Stream, Preset, Announcement
from .amplipi import AmpliPi
from .error import APIError

Expand Down Expand Up @@ -144,7 +144,7 @@ async def do_config_load(args: Namespace, amplipi: AmpliPi, shell: bool, **kwarg
"""
log.debug(f"config.load(«stdin») forced = {args.force}")
# Be sure to consume stdin before entering interactive dialogue
new_config: Status = instantiate_model(Status, args.infile) # not using any --input and no validate()
new_config: Config = instantiate_model(Config, args.infile) # not using any --input and no validate()
# Make sure the user wants this
assert args.force or interactive_confirm("You are about to overwrite the configuration."), "Aborted"
await amplipi.load_config(new_config) # ignoring status return value
Expand Down
4 changes: 2 additions & 2 deletions pyamplipi/amplipi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pyamplipi.client import Client
from pyamplipi.models import Group, Stream, SourceUpdate, MultiZoneUpdate, ZoneUpdate, \
GroupUpdate, StreamUpdate, Announcement, Status, Source, Zone, Preset
GroupUpdate, StreamUpdate, Announcement, Status, Config, Source, Zone, Preset

json_ser_kwargs = dict(exclude_unset=True)

Expand All @@ -30,7 +30,7 @@ async def get_status(self) -> Status:
response = await self._client.get('')
return Status.parse_obj(response)

async def load_config(self, config: Status) -> Status:
async def load_config(self, config: Config) -> Status:
response = await self._client.post('load', config.json(**json_ser_kwargs))
return Status.parse_obj(response)

Expand Down
5 changes: 4 additions & 1 deletion pyamplipi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,15 @@ class Info(BaseModel):
fw: Optional[List[FirmwareInfo]]


class Status(BaseModel):
class Config(BaseModel):
sources: List[Source] = []
zones: List[Zone] = []
groups: List[Group] = []
streams: List[Stream] = []
presets: List[Preset] = []


class Status(Config):
info: Optional[Info]


Expand Down

0 comments on commit e67f5b1

Please sign in to comment.