started ControllerDaylight
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import timedelta
|
||||
from datetime import datetime, timedelta
|
||||
from html import entities
|
||||
from typing import List
|
||||
|
||||
from appdaemon.adapi import ADAPI
|
||||
from appdaemon.entity import Entity
|
||||
|
||||
from appdaemon.plugins.hass.hassapi import Hass
|
||||
from daylight_adjuster import DaylightAdjuster
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
@@ -26,6 +26,7 @@ class ControllerBase(Hass):
|
||||
|
||||
self.log(f'Initialized controller for {[e.friendly_name for e in self.entities]}')
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class ControllerRoom(ControllerBase):
|
||||
def initialize(self):
|
||||
@@ -47,6 +48,7 @@ class ControllerRoom(ControllerBase):
|
||||
def state(self) -> bool:
|
||||
return any([e.get_state() == 'on' for e in self.entities])
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class ControllerMotion(ControllerBase):
|
||||
room: ControllerRoom
|
||||
@@ -67,7 +69,6 @@ class ControllerMotion(ControllerBase):
|
||||
self.off_duration = timedelta()
|
||||
|
||||
self.sync_state()
|
||||
|
||||
self.listen_state(self.sync_state, [e.entity_id for e in self.entities])
|
||||
|
||||
@property
|
||||
@@ -115,6 +116,7 @@ class ControllerMotion(ControllerBase):
|
||||
self.log(f'Motion stopped on {self.friendly_name(entity)} for {self.off_duration}')
|
||||
self.room.deactivate()
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class ControllerButton(Hass):
|
||||
room: ControllerRoom
|
||||
@@ -133,7 +135,7 @@ class ControllerButton(Hass):
|
||||
id=button,
|
||||
)
|
||||
self.log(f'Listening to presses on button ID={button}')
|
||||
|
||||
|
||||
def callback_button(self, event_name, data, kwargs):
|
||||
# single press
|
||||
if data['event'] == 1002:
|
||||
@@ -142,4 +144,31 @@ class ControllerButton(Hass):
|
||||
self.room.deactivate()
|
||||
else:
|
||||
self.room.activate()
|
||||
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class ControllerDaylight(ControllerBase):
|
||||
latitude: float
|
||||
longitude: float
|
||||
|
||||
def initialize(self):
|
||||
super().initialize()
|
||||
self.adjuster = DaylightAdjuster(
|
||||
latitude=self.args['latitude'],
|
||||
longitude=self.args['longitude'],
|
||||
periods=self.args['periods'],
|
||||
resolution=500
|
||||
)
|
||||
self.log(self.adjuster)
|
||||
self.listen_state(callback=self.adjust, entity_id=[e.entity_id for e in self.entities])
|
||||
self.log(f'Listening for state {[e.friendly_name for e in self.entities]}')
|
||||
|
||||
def adjust(self, entity, attribute, old, new, kwargs):
|
||||
if new == 'on':
|
||||
self.adjustment_handle = self.run_every(callback=self.ongoing_adjustment, start='now', interval=10, entity=entity)
|
||||
else:
|
||||
self.log(f'Cancelling adjustments')
|
||||
self.cancel_timer(self.adjustment_handle)
|
||||
|
||||
def ongoing_adjustment(self, kwargs):
|
||||
self.log(f'Adjusting {self.friendly_name(kwargs["entity"])}')
|
||||
|
||||
@@ -11,11 +11,40 @@ kitchen_motion:
|
||||
off_duration: 00:01:00
|
||||
entities:
|
||||
- binary_sensor.motion_kitchen
|
||||
# - binary_sensor.motion_bedroom
|
||||
|
||||
kitchen_button:
|
||||
module: controller
|
||||
class: ControllerButton
|
||||
room: kitchen
|
||||
buttons:
|
||||
- kitchen
|
||||
- kitchen
|
||||
|
||||
kitchen_daylight:
|
||||
module: controller
|
||||
class: ControllerDaylight
|
||||
entities:
|
||||
- light.kitchen
|
||||
latitude: 30.150380
|
||||
longitude: -97.4487
|
||||
periods:
|
||||
- time: '04:00:00am'
|
||||
brightness: 75
|
||||
color_temp: 200
|
||||
|
||||
- elevation: 0
|
||||
direction: rising
|
||||
brightness: 150
|
||||
color_temp: 200
|
||||
|
||||
- time: noon
|
||||
brightness: 255
|
||||
color_temp: 300
|
||||
|
||||
- elevation: 0
|
||||
direction: setting
|
||||
brightness: 125
|
||||
color_temp: 325
|
||||
|
||||
- time: '10:30:00pm'
|
||||
brightness: 75
|
||||
color_temp: 350
|
||||
Reference in New Issue
Block a user