diff --git a/apps/tv.py b/apps/tv.py index 173843c..8a742af 100644 --- a/apps/tv.py +++ b/apps/tv.py @@ -1,5 +1,4 @@ -from dataclasses import dataclass, field, fields -from datetime import timedelta +from dataclasses import dataclass, fields from appdaemon.entity import Entity from appdaemon.plugins.hass.hassapi import Hass @@ -8,10 +7,11 @@ from appdaemon.plugins.hass.hassapi import Hass @dataclass(init=False) class SoundBar(Hass): """Turns on the soundbar by sending a command with the Broadlink remote. - - Turns on when the playing_entity goes to playing - - Turns off when the off_entity turns off + - Turns on when the playing_entity goes to playing + - Turns off when the off_entity turns off """ + device: str remote_entity: Entity playing_entity: Entity @@ -19,7 +19,7 @@ class SoundBar(Hass): def initialize(self): self.set_fields() - + self.listen_state(self.turn_on_soundbar, self.playing_entity.entity_id, new='playing') self.log(f'Waiting for {self.playing_entity} to go to playing') @@ -32,13 +32,13 @@ class SoundBar(Hass): arg = self.args[f.name] if f.type == Entity: if not self.entity_exists(arg): - self.log(f'{arg} does not exist', level="WARNING") + self.log(f'{arg} does not exist', level='WARNING') else: setattr(self, f.name, self.get_entity(arg)) else: setattr(self, f.name, arg) else: - self.log(f'{f.name} field is unset', level="WARNING") + self.log(f'{f.name} field is unset', level='WARNING') self.log(repr(self)) def send_remote_command(self, command: str): @@ -48,10 +48,7 @@ class SoundBar(Hass): self.log(f'Sending remote command: {command}') self.call_service( - service='remote/send_command', - entity_id=self.remote_entity.entity_id, - device='BoseTV', - command=command + service='remote/send_command', entity_id=self.remote_entity.entity_id, device='BoseTV', command=command ) def turn_on_soundbar(self, entity=None, attribute=None, old=None, new=None, kwargs=None):