updated for rich logging stuff
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
import sys
|
import sys
|
||||||
from copy import deepcopy
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from appdaemon.plugins.hass.hassapi import Hass
|
from appdaemon.plugins.hass.hassapi import Hass
|
||||||
@@ -8,39 +8,45 @@ from appdaemon.plugins.mqtt.mqttapi import Mqtt
|
|||||||
|
|
||||||
rc_path = (Path(__file__).resolve().parents[1] / 'room_control').as_posix()
|
rc_path = (Path(__file__).resolve().parents[1] / 'room_control').as_posix()
|
||||||
sys.path.insert(0, rc_path)
|
sys.path.insert(0, rc_path)
|
||||||
|
from console import console, setup_component_logging
|
||||||
from console import console, init_logging, deinit_logging
|
|
||||||
|
|
||||||
|
|
||||||
class AqaraCube(Hass, Mqtt):
|
class AqaraCube(Hass, Mqtt):
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
if (level := self.args.get('rich', False)):
|
setup_component_logging(self)
|
||||||
init_logging(self, level)
|
self.logger.setLevel(logging.DEBUG)
|
||||||
|
# self.logger = logging.getLogger()
|
||||||
|
|
||||||
|
# if (level := self.args.get('rich', False)):
|
||||||
|
# init_logging(self, level)
|
||||||
|
|
||||||
|
# for name, logger in logging.Logger.manager.loggerDict.items():
|
||||||
|
# logger = logging.getLogger(name)
|
||||||
|
# if logger.hasHandlers():
|
||||||
|
# self.log(f'[yellow]{name.ljust(25)}[/]{type(logger).__name__}', )
|
||||||
|
# for handler in logger.handlers:
|
||||||
|
# self.log(f' {type(handler).__name__}: {type(handler.formatter).__name__}')
|
||||||
|
|
||||||
topic = f'zigbee2mqtt/{self.args["cube"]}'
|
topic = f'zigbee2mqtt/{self.args["cube"]}'
|
||||||
self.mqtt_subscribe(topic, namespace='mqtt')
|
self.mqtt_subscribe(topic, namespace='mqtt')
|
||||||
self.listen_event(self.handle_event, 'MQTT_MESSAGE', topic=topic, namespace='mqtt')
|
self.listen_event(self.handle_event, 'MQTT_MESSAGE', topic=topic, namespace='mqtt')
|
||||||
self.log(f'Listening for cube events on: {topic}')
|
self.log(f'Listening for cube events on: [topic]{topic}[/]')
|
||||||
|
|
||||||
self.app = self.get_app(self.args['app'])
|
self.app = self.get_app(self.args['app'])
|
||||||
self.log(f'Connected to other app: {self.app.name}')
|
self.log(f'Connected to AD app: [room]{self.app.name}[/]')
|
||||||
|
|
||||||
def terminate(self):
|
def terminate(self):
|
||||||
self.log('[bold red]Terminating[/]', level='DEBUG')
|
self.log('[bold red]Terminating[/]', level='DEBUG')
|
||||||
deinit_logging(self)
|
|
||||||
self.log('Success', level='DEBUG')
|
|
||||||
|
|
||||||
def handle_event(self, event_name, data, cb_args):
|
def handle_event(self, event_name, data, cb_args):
|
||||||
topic_prefix, cube_name = data['topic'].split('/')
|
|
||||||
self.log(f'{event_name} on [bright_black]{topic_prefix}/[/][blue]{cube_name}[/]', data, level='DEBUG')
|
|
||||||
|
|
||||||
payload = json.loads(data['payload'])
|
payload = json.loads(data['payload'])
|
||||||
action = payload['action']
|
action = payload['action']
|
||||||
|
|
||||||
if action == '' or action == 'wakeup':
|
if action == '' or action == 'wakeup':
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self.log(json.dumps(payload, indent=2), level='DEBUG')
|
log_msg = f'{event_name} on [topic]{data["topic"]}[/], Action: "[yellow]{str(action)}[/]"\n'
|
||||||
|
self.log(log_msg + json.dumps(payload, indent=2), level='DEBUG')
|
||||||
if (arg := self.args.get(action, False)):
|
if (arg := self.args.get(action, False)):
|
||||||
self.action_handler(action=action, description=arg)
|
self.action_handler(action=action, description=arg)
|
||||||
elif handler := getattr(self, f'handle_{action}', None):
|
elif handler := getattr(self, f'handle_{action}', None):
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
cube1:
|
cube1:
|
||||||
module: cube
|
module: cube
|
||||||
class: AqaraCube
|
class: AqaraCube
|
||||||
rich: INFO
|
rich: DEBUG
|
||||||
cube: Cube 1
|
cube: Cube 1
|
||||||
app: bedroom
|
app: bedroom
|
||||||
flip90: toggle
|
flip90: toggle
|
||||||
|
|||||||
Submodule apps/room_control updated: d8a9d3d83a...541475d68b
@@ -1,6 +1,7 @@
|
|||||||
bathroom:
|
bathroom:
|
||||||
module: room_control
|
module: room_control
|
||||||
class: RoomController
|
class: RoomController
|
||||||
|
# rich: DEBUG
|
||||||
off_duration: '00:05:00'
|
off_duration: '00:05:00'
|
||||||
states:
|
states:
|
||||||
- time: '05:00:00'
|
- time: '05:00:00'
|
||||||
@@ -34,6 +35,7 @@ bathroom:
|
|||||||
bathroom_button:
|
bathroom_button:
|
||||||
module: button
|
module: button
|
||||||
class: Button
|
class: Button
|
||||||
|
# rich: DEBUG
|
||||||
app: bathroom
|
app: bathroom
|
||||||
button: Bathroom Button
|
button: Bathroom Button
|
||||||
ref_entity: light.bathroom
|
ref_entity: light.bathroom
|
||||||
@@ -41,6 +43,7 @@ bathroom_button:
|
|||||||
bathroom_motion:
|
bathroom_motion:
|
||||||
module: motion
|
module: motion
|
||||||
class: Motion
|
class: Motion
|
||||||
|
# rich: DEBUG
|
||||||
app: bathroom
|
app: bathroom
|
||||||
sensor: binary_sensor.bathroom_motion_occupancy
|
sensor: binary_sensor.bathroom_motion_occupancy
|
||||||
ref_entity: light.bathroom
|
ref_entity: light.bathroom
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
bedroom:
|
bedroom:
|
||||||
module: room_control
|
module: room_control
|
||||||
class: RoomController
|
class: RoomController
|
||||||
|
# rich: DEBUG
|
||||||
off_duration: '00:05:00'
|
off_duration: '00:05:00'
|
||||||
states:
|
states:
|
||||||
- time: 'sunrise - 03:00:00'
|
- time: 'sunrise - 03:00:00'
|
||||||
@@ -76,6 +77,7 @@ bedroom:
|
|||||||
bedroom_buttons:
|
bedroom_buttons:
|
||||||
module: button
|
module: button
|
||||||
class: Button
|
class: Button
|
||||||
|
# rich: DEBUG
|
||||||
app: bedroom
|
app: bedroom
|
||||||
ref_entity: light.bedroom
|
ref_entity: light.bedroom
|
||||||
button:
|
button:
|
||||||
@@ -84,7 +86,8 @@ bedroom_buttons:
|
|||||||
|
|
||||||
bedroom_motion:
|
bedroom_motion:
|
||||||
module: motion
|
module: motion
|
||||||
class: Motion
|
class: Motion
|
||||||
|
# rich: DEBUG
|
||||||
app: bedroom
|
app: bedroom
|
||||||
sensor: binary_sensor.bedroom_motion_occupancy
|
sensor: binary_sensor.bedroom_motion_occupancy
|
||||||
off_duration: '00:05:00'
|
off_duration: '00:05:00'
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
closet:
|
closet:
|
||||||
module: room_control
|
module: room_control
|
||||||
class: RoomController
|
class: RoomController
|
||||||
|
# rich: DEBUG
|
||||||
off_duration: '00:02:00'
|
off_duration: '00:02:00'
|
||||||
states:
|
states:
|
||||||
- time: 'sunrise - 03:00:00'
|
- time: 'sunrise - 03:00:00'
|
||||||
@@ -26,7 +27,8 @@ closet:
|
|||||||
|
|
||||||
closet_motion:
|
closet_motion:
|
||||||
module: motion
|
module: motion
|
||||||
class: Motion
|
class: Motion
|
||||||
|
# rich: DEBUG
|
||||||
app: closet
|
app: closet
|
||||||
sensor: binary_sensor.closet_motion_occupancy
|
sensor: binary_sensor.closet_motion_occupancy
|
||||||
ref_entity: light.closet
|
ref_entity: light.closet
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
kitchen:
|
kitchen:
|
||||||
module: room_control
|
module: room_control
|
||||||
class: RoomController
|
class: RoomController
|
||||||
|
# rich: DEBUG
|
||||||
off_duration: '00:10:00'
|
off_duration: '00:10:00'
|
||||||
# ha_button: input_button.activate_kitchen
|
# ha_button: input_button.activate_kitchen
|
||||||
sleep: input_boolean.sleeping
|
sleep: input_boolean.sleeping
|
||||||
@@ -39,13 +40,15 @@ kitchen:
|
|||||||
kitchen_button:
|
kitchen_button:
|
||||||
module: button
|
module: button
|
||||||
class: Button
|
class: Button
|
||||||
|
# rich: DEBUG
|
||||||
app: kitchen
|
app: kitchen
|
||||||
button: Kitchen Button
|
button: Kitchen Button
|
||||||
ref_entity: light.kitchen
|
ref_entity: light.kitchen
|
||||||
|
|
||||||
kitchen_motion:
|
kitchen_motion:
|
||||||
module: motion
|
module: motion
|
||||||
class: Motion
|
class: Motion
|
||||||
|
# rich: DEBUG
|
||||||
app: kitchen
|
app: kitchen
|
||||||
sensor: binary_sensor.kitchen_motion_occupancy
|
sensor: binary_sensor.kitchen_motion_occupancy
|
||||||
ref_entity: light.kitchen
|
ref_entity: light.kitchen
|
||||||
35
apps/rooms/laundry.yaml
Normal file
35
apps/rooms/laundry.yaml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
laundry:
|
||||||
|
module: room_control
|
||||||
|
class: RoomController
|
||||||
|
# rich: DEBUG
|
||||||
|
off_duration: '00:02:00'
|
||||||
|
states:
|
||||||
|
- time: 'sunrise - 03:00:00'
|
||||||
|
scene:
|
||||||
|
light.laundry:
|
||||||
|
brightness: 25
|
||||||
|
color_temp: 200
|
||||||
|
- time: 'sunrise'
|
||||||
|
scene:
|
||||||
|
light.laundry:
|
||||||
|
brightness: 75
|
||||||
|
color_temp: 200
|
||||||
|
- time: '12:00:00'
|
||||||
|
scene:
|
||||||
|
light.laundry:
|
||||||
|
brightness: 175
|
||||||
|
color_temp: 300
|
||||||
|
- time: sunset
|
||||||
|
scene:
|
||||||
|
light.laundry:
|
||||||
|
brightness: 100
|
||||||
|
color_temp: 400
|
||||||
|
|
||||||
|
laundry_motion:
|
||||||
|
module: motion
|
||||||
|
class: Motion
|
||||||
|
# rich: DEBUG
|
||||||
|
rich: DEBUG
|
||||||
|
app: laundry
|
||||||
|
sensor: binary_sensor.laundry_motion_occupancy
|
||||||
|
ref_entity: light.laundry
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
living_room:
|
living_room:
|
||||||
module: room_control
|
module: room_control
|
||||||
class: RoomController
|
class: RoomController
|
||||||
|
# rich: DEBUG
|
||||||
off_duration: 00:30:00
|
off_duration: 00:30:00
|
||||||
states:
|
states:
|
||||||
- time: sunrise
|
- time: sunrise
|
||||||
@@ -68,19 +69,22 @@ living_room:
|
|||||||
front_door:
|
front_door:
|
||||||
module: door
|
module: door
|
||||||
class: Door
|
class: Door
|
||||||
|
# rich: DEBUG
|
||||||
app: living_room
|
app: living_room
|
||||||
door: binary_sensor.front_contact
|
door: binary_sensor.front_contact
|
||||||
|
|
||||||
living_room_button:
|
living_room_button:
|
||||||
module: button
|
module: button
|
||||||
class: Button
|
class: Button
|
||||||
|
# rich: DEBUG
|
||||||
app: living_room
|
app: living_room
|
||||||
button: Living Room Button
|
button: Living Room Button
|
||||||
ref_entity: light.living_room
|
ref_entity: light.living_room
|
||||||
|
|
||||||
living_room_motion:
|
living_room_motion:
|
||||||
module: motion
|
module: motion
|
||||||
class: Motion
|
class: Motion
|
||||||
|
# rich: DEBUG
|
||||||
app: living_room
|
app: living_room
|
||||||
sensor: binary_sensor.living_room_motion_occupancy
|
sensor: binary_sensor.living_room_motion_occupancy
|
||||||
ref_entity: light.living_room
|
ref_entity: light.living_room
|
||||||
|
|||||||
@@ -2,4 +2,5 @@
|
|||||||
# pvlib --only-binary=:pvlib:
|
# pvlib --only-binary=:pvlib:
|
||||||
# matplotlib --only-binary=:matplotlib:
|
# matplotlib --only-binary=:matplotlib:
|
||||||
# jupyterlab --only-binary=:jupyterlab:
|
# jupyterlab --only-binary=:jupyterlab:
|
||||||
rich
|
rich
|
||||||
|
pydantic
|
||||||
Reference in New Issue
Block a user