handling multiple buttons
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from dataclasses import dataclass
|
||||
from logging import Logger, LoggerAdapter
|
||||
from logging import LoggerAdapter
|
||||
|
||||
from appdaemon.adapi import ADAPI
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from typing import Annotated, Dict, List, Optional, Self
|
||||
|
||||
import yaml
|
||||
from astral import SunDirection
|
||||
from pydantic import BaseModel, BeforeValidator, Field, model_validator, root_validator
|
||||
from pydantic import BaseModel, BeforeValidator, Field, model_validator
|
||||
from pydantic_core import PydanticCustomError
|
||||
from rich.console import Console, ConsoleOptions, RenderResult
|
||||
from rich.table import Column, Table
|
||||
@@ -53,10 +53,7 @@ class ControllerStateConfig(BaseModel):
|
||||
|
||||
@model_validator(mode='before')
|
||||
def check_args(cls, values):
|
||||
time, elevation = values.get('time'), values.get('elevation')
|
||||
# if time is not None and elevation is not None:
|
||||
# raise PydanticCustomError('bad_time_spec', 'Only one of time or elevation can be set.')
|
||||
if elevation is not None and 'direction' not in values:
|
||||
if values.get('elevation') is not None and values.get('direction') is None:
|
||||
raise PydanticCustomError('no_sun_dir', 'Needs sun direction with elevation')
|
||||
return values
|
||||
|
||||
|
||||
@@ -79,6 +79,8 @@ class RoomController(Hass):
|
||||
if button := self.args.get('button'):
|
||||
if isinstance(button, str):
|
||||
self.button = Button(self, button_name=button)
|
||||
elif isinstance(button, list) and all(isinstance(b, str) for b in button):
|
||||
self.button = [Button(self, button_name=b) for b in button]
|
||||
|
||||
if door := self.args.get('door'):
|
||||
if isinstance(door, str):
|
||||
@@ -166,7 +168,7 @@ class RoomController(Hass):
|
||||
self.call_service(f'{self.name}/activate', namespace='controller', **kwargs)
|
||||
|
||||
def _service_activate(self, namespace: str, domain: str, service: str, kwargs: Dict[str, Any]):
|
||||
self.log(f'Custom kwargs: {kwargs}', level='DEBUG')
|
||||
# self.log(f'Custom kwargs: {kwargs}', level='DEBUG')
|
||||
state = self.current_state()
|
||||
if isinstance(state.scene, str):
|
||||
self.turn_on(state.scene)
|
||||
|
||||
Reference in New Issue
Block a user