expert import mode

This commit is contained in:
John Lancaster
2024-05-02 22:49:46 -05:00
parent aedee1ac12
commit a38341484d
10 changed files with 21 additions and 26 deletions

View File

@@ -1,16 +1,11 @@
import logging
import sys
from enum import Enum
from pathlib import Path
from typing import Literal, Optional
from appdaemon.plugins.hass.hassapi import Hass
from appdaemon.plugins.mqtt.mqttapi import Mqtt
from pydantic import BaseModel, Field, TypeAdapter, field_validator
rc_path = (Path(__file__).resolve().parents[1] / 'room_control').as_posix()
sys.path.insert(0, rc_path)
from console import console, setup_component_logging
from room_control.console import setup_component_logging
class Side(int, Enum):
@@ -20,13 +15,10 @@ class Side(int, Enum):
front = 3
left = 4
bottom = 5
Actions = Literal[
'', 'wakeup',
'slide', 'shake',
'rotate_left', 'rotate_right',
'flip180', 'flip90'
'', 'wakeup', 'slide', 'shake', 'rotate_left', 'rotate_right', 'flip180', 'flip90'
]
@@ -104,9 +96,9 @@ class AqaraCube(Hass, Mqtt):
else:
self.log(
f'{event_name} on [topic]{data.topic}[/], Action: "[yellow]{str(action)}[/]"',
level='DEBUG'
level='DEBUG',
)
if (arg := self.args.get(action, False)):
if arg := self.args.get(action, False):
self.action_handler(action=action, description=arg)
elif handler := getattr(self, f'handle_{action}', None):
handler(data.payload)