fixed soundbar turning on
This commit is contained in:
@@ -5,9 +5,10 @@ hello_world:
|
|||||||
living_room_tv:
|
living_room_tv:
|
||||||
module: tv
|
module: tv
|
||||||
class: LivingRoomTV
|
class: LivingRoomTV
|
||||||
media_entity: media_player.living_room_tv
|
|
||||||
hardware_entity: media_player.sony_kd_65x85k
|
|
||||||
remote_entity: remote.broadlink_remote
|
remote_entity: remote.broadlink_remote
|
||||||
|
playing_entity: media_player.sony_google_cast
|
||||||
|
# media_entity: media_player.living_room_tv
|
||||||
|
# hardware_entity: media_player.sony_kd_65x85k
|
||||||
|
|
||||||
scene_detect:
|
scene_detect:
|
||||||
module: scene_detect
|
module: scene_detect
|
||||||
|
|||||||
55
apps/tv.py
55
apps/tv.py
@@ -7,28 +7,38 @@ from appdaemon.plugins.hass.hassapi import Hass
|
|||||||
|
|
||||||
@dataclass(init=False)
|
@dataclass(init=False)
|
||||||
class LivingRoomTV(Hass):
|
class LivingRoomTV(Hass):
|
||||||
media_entity: str
|
remote_entity: str = None
|
||||||
hardware_entity: str
|
playing_entity: str = None
|
||||||
remote_entity: str
|
# media_entity: str = None
|
||||||
|
# hardware_entity: str = None
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
self.listen_state(self.turn_on_soundbar, self.args['playing_entity'], new='playing')
|
self.log(self.args)
|
||||||
|
for f in fields(self):
|
||||||
|
if f.name in self.args:
|
||||||
|
entity_id = self.args[f.name]
|
||||||
|
if not self.entity_exists(entity_id):
|
||||||
|
self.log(f'{entity_id} does not exist', level="WARNING")
|
||||||
|
else:
|
||||||
|
setattr(self, f.name, entity_id)
|
||||||
|
else:
|
||||||
|
self.log(f'{f.name} field is unset', level="WARNING")
|
||||||
|
self.log(repr(self))
|
||||||
|
|
||||||
for entity in self.args['track_entities']:
|
self.listen_state(self.turn_on_soundbar, self.playing_entity, new='playing')
|
||||||
self.listen_state(self.state_change, entity, attribute='all')
|
self.log(f'Waiting for {self.playing_entity} to go to playing')
|
||||||
self.log(f'Tracking state changes: {entity}')
|
|
||||||
|
|
||||||
def turn_on_soundbar(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
|
def turn_on_soundbar(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
|
||||||
if self.get_state(self.args['remote_entity']) != 'on':
|
if self.get_state(self.remote_entity) != 'on':
|
||||||
self.log('Turning on remote')
|
self.log('Turning on remote')
|
||||||
self.turn_on(self.args['remote_entity'])
|
self.turn_on(self.remote_entity)
|
||||||
# if self.remote_entity.state != 'on':
|
# if self.remote_entity.state != 'on':
|
||||||
# self.log('Turning on remote')
|
# self.log('Turning on remote')
|
||||||
# self.remote_entity.turn_on()
|
# self.remote_entity.turn_on()
|
||||||
|
|
||||||
self.log('Turning on soundbar')
|
self.log('Turning on soundbar')
|
||||||
self.call_service(service='remote/send_command',
|
self.call_service(service='remote/send_command',
|
||||||
entity_id=self.args['remote_entity'],
|
entity_id=self.remote_entity,
|
||||||
device='BoseTV', command='TV')
|
device='BoseTV', command='TV')
|
||||||
|
|
||||||
def state_change(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
|
def state_change(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
|
||||||
@@ -43,31 +53,6 @@ class LivingRoomTV(Hass):
|
|||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
self.log(f'Failed getting attribute {e} from {entity}')
|
self.log(f'Failed getting attribute {e} from {entity}')
|
||||||
|
|
||||||
# def recast_lovelace(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
|
|
||||||
# self.cancel_callbacks()
|
|
||||||
# if new['state'] == 'playing':
|
|
||||||
# if 'lovelace' in (app_name := new['attributes']['app_name']).lower():
|
|
||||||
# delay = timedelta(minutes=9, seconds=30)
|
|
||||||
# self.log(f'Recasting Lovelace in {delay}')
|
|
||||||
# self.run_in(
|
|
||||||
# callback=lambda kwargs: self.media_entity.turn_off(),
|
|
||||||
# delay=delay.total_seconds()
|
|
||||||
# )
|
|
||||||
# self.run_in(
|
|
||||||
# callback=self.cast_lovelace,
|
|
||||||
# delay=delay.total_seconds() + 5
|
|
||||||
# )
|
|
||||||
# else:
|
|
||||||
# self.log(f'Playing {app_name}')
|
|
||||||
|
|
||||||
# def cast_lovelace(self, kwargs=None):
|
|
||||||
# self.call_service(
|
|
||||||
# 'cast/show_lovelace_view',
|
|
||||||
# view_path='tv',
|
|
||||||
# dashboard_path='lovelace',
|
|
||||||
# entity_id=self.media_entity.entity_id,
|
|
||||||
# )
|
|
||||||
|
|
||||||
def cancel_callbacks(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
|
def cancel_callbacks(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
|
||||||
if (callbacks := self.get_scheduler_entries().get(self.name)):
|
if (callbacks := self.get_scheduler_entries().get(self.name)):
|
||||||
for handle, info in callbacks.items():
|
for handle, info in callbacks.items():
|
||||||
|
|||||||
Reference in New Issue
Block a user