started gone app
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
hello-world:
|
||||
module: hello
|
||||
class: HelloWorld
|
||||
|
||||
gone:
|
||||
module: gone
|
||||
class: Gone
|
||||
entities:
|
||||
- light.bar
|
||||
- light.h6076
|
||||
- light.h6076_2
|
||||
|
||||
27
apps/gone.py
Normal file
27
apps/gone.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from typing import Any
|
||||
|
||||
from appdaemon.plugins.hass import Hass
|
||||
|
||||
|
||||
class Gone(Hass):
|
||||
def initialize(self):
|
||||
people = self.get_state('person')
|
||||
# self.log(json.dumps(people, indent=2))
|
||||
|
||||
self.log(list(people.keys()))
|
||||
for person in self.get_state('person'):
|
||||
self.listen_state(self.handle_state, entity_id=person, new='not_home')
|
||||
|
||||
self.log(f'No one home: {self.no_one_home()}')
|
||||
|
||||
def no_one_home(self) -> bool:
|
||||
return all(state.get('state') != 'home' for state in self.get_state('person', copy=False).values())
|
||||
|
||||
def handle_state(self, entity: str, attribute: str, old: Any, new: Any, **kwargs: Any) -> None:
|
||||
if self.no_one_home():
|
||||
for ent in self.args['entities']:
|
||||
try:
|
||||
self.turn_off(ent)
|
||||
except Exception:
|
||||
self.log(f'Failed to turn off {ent}', level='ERROR')
|
||||
continue
|
||||
Reference in New Issue
Block a user