From a93031c35b54168e93148144fbe3e4286255a0bd Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Wed, 30 Aug 2023 16:56:45 -0500 Subject: [PATCH] update --- greendeck/config.py | 15 +++++++++++---- greendeck/main.py | 11 +++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/greendeck/config.py b/greendeck/config.py index 81d9000..74b8376 100644 --- a/greendeck/config.py +++ b/greendeck/config.py @@ -1,8 +1,15 @@ -from typing import Annotated, Literal, Union +from typing import Annotated +from typing import Literal +from typing import Union -from pydantic import BaseModel, Field, ValidationError, root_validator, validator +from pydantic import BaseModel +from pydantic import Field +from pydantic import ValidationError +from pydantic import root_validator +from pydantic import validator from pydantic.color import Color -from pydantic_yaml import YamlModel + +# from pydantic_yaml import YamlModel from typing_extensions import Self @@ -130,7 +137,7 @@ class TileConfig(BaseModel): actions: list[ActionConfig] -class Config(YamlModel): +class Config(BaseModel): homeassistant: HomeAssistantConfig streamdecks: list[StreamDeckConfig] screens: dict[str, list[TileConfig]] diff --git a/greendeck/main.py b/greendeck/main.py index b3ab8f1..c9240c5 100644 --- a/greendeck/main.py +++ b/greendeck/main.py @@ -8,6 +8,7 @@ import click # from PIL import ImageDraw # from PIL import ImageFont from pydantic import parse_obj_as +from pydantic_yaml import parse_yaml_raw_as from typing_extensions import Self from greendeck.config import Config @@ -74,7 +75,6 @@ class DeckHandler: return None async def start(self: Self): - await self.deck.open() await self.deck.reset() @@ -102,7 +102,6 @@ class DeckHandler: async def update_key_state( self: Self, key: int, old_state: bool | None, new_state: bool ) -> None: - self.key_states[key] = new_state if new_state is False: @@ -126,7 +125,6 @@ class DeckHandler: t.add_done_callback(task_done_callback) async def update_key_image(self: Self, key: int) -> None: - tile_config = self.get_tile_config_for_key(key) if tile_config is None: @@ -141,7 +139,6 @@ class DeckHandler: ) case "homeassistant-icon": - home_assistant_icon_image_config = parse_obj_as( HomeAssistantIconImageConfig, tile_config.image ) @@ -174,7 +171,6 @@ class DeckHandler: old_state: bool | None, new_state: bool, ) -> None: - assert self.deck.serial_number == deck.serial_number position = self.convert_key_to_position(key) @@ -214,14 +210,12 @@ class DeckHandler: key: int, event: EventResponse, ) -> None: - self.homeassistant_states[key] = event.event.data.new_state.state t = asyncio.create_task(self.update_key_image(key)) t.add_done_callback(task_done_callback) async def update_homeassistant_callbacks(self: Self, key: int): - tile_config = self.get_tile_config_for_key(key) if tile_config is None: return @@ -331,7 +325,8 @@ def main( config_path: pathlib.Path, ): setup_logging() - config = Config.parse_raw(config_path.read_bytes(), proto="yaml") + # config = Config.parse_raw(config_path.read_bytes(), proto="yaml") + config: Config = parse_yaml_raw_as(Config, config_path.read_bytes()) asyncio.run(_main(config))