broke out the hardware entity
This commit is contained in:
@@ -5,5 +5,6 @@ hello_world:
|
|||||||
living_room_tv:
|
living_room_tv:
|
||||||
module: tv
|
module: tv
|
||||||
class: LivingRoomTV
|
class: LivingRoomTV
|
||||||
tv_entity: media_player.living_room_tv
|
media_entity: media_player.living_room_tv
|
||||||
|
hardware_entity: media_player.sony_kd_65x85k
|
||||||
remote_entity: remote.broadlink_remote
|
remote_entity: remote.broadlink_remote
|
||||||
|
|||||||
32
apps/tv.py
32
apps/tv.py
@@ -7,21 +7,26 @@ from appdaemon.plugins.hass.hassapi import Hass
|
|||||||
|
|
||||||
@dataclass(init=False)
|
@dataclass(init=False)
|
||||||
class LivingRoomTV(Hass):
|
class LivingRoomTV(Hass):
|
||||||
tv_entity: str
|
media_entity: str
|
||||||
|
hardware_entity: str
|
||||||
remote_entity: str
|
remote_entity: str
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
self.log(f'Media Player Entity: {self.tv_entity.friendly_name} ({self.tv_entity.entity_id})')
|
self.log(f'Media Player Entity: {self.media_entity.friendly_name} ({self.media_entity.entity_id})')
|
||||||
self.log(f'Remote Entity: {self.remote_entity.friendly_name} ({self.remote_entity.entity_id})')
|
self.log(f'Remote Entity: {self.remote_entity.friendly_name} ({self.remote_entity.entity_id})')
|
||||||
|
|
||||||
self.listen_state(self.turn_on_soundbar, self.tv_entity.entity_id, new='playing')
|
self.listen_state(self.turn_on_soundbar, self.media_entity.entity_id, new='playing')
|
||||||
self.listen_state(self.debug_state, self.tv_entity.entity_id)
|
self.listen_state(self.debug_state, self.media_entity.entity_id)
|
||||||
self.listen_state(self.recast_lovelace, self.tv_entity.entity_id, attribute='all')
|
self.listen_state(self.recast_lovelace, self.media_entity.entity_id, attribute='all')
|
||||||
# self.listen_state(self.cancel_callbacks, 'media_player.sony_kd_65x85k', new='off')
|
self.listen_state(self.hardware_off_callback, self.hardware_entity.entity_id, new='off')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tv_entity(self) -> Entity:
|
def media_entity(self) -> Entity:
|
||||||
return self.get_entity(self.args['tv_entity'])
|
return self.get_entity(self.args['media_entity'])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def hardware_entity(self) -> Entity:
|
||||||
|
return self.get_entity(self.args['hardware_entity'])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def remote_entity(self) -> Entity:
|
def remote_entity(self) -> Entity:
|
||||||
@@ -36,19 +41,19 @@ class LivingRoomTV(Hass):
|
|||||||
self.remote_entity.turn_on()
|
self.remote_entity.turn_on()
|
||||||
|
|
||||||
self.log('Turning on soundbar')
|
self.log('Turning on soundbar')
|
||||||
|
# self.remote_entity.call_service('remote/send_command', device='BoseTV', command='TV')
|
||||||
self.call_service(service='remote/send_command',
|
self.call_service(service='remote/send_command',
|
||||||
entity_id=self.remote_entity.entity_id,
|
entity_id=self.remote_entity.entity_id,
|
||||||
device='BoseTV', command='TV')
|
device='BoseTV', command='TV')
|
||||||
|
|
||||||
def recast_lovelace(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
|
def recast_lovelace(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
|
||||||
# self.log(f'{new}')
|
|
||||||
self.cancel_callbacks()
|
self.cancel_callbacks()
|
||||||
if new['state'] == 'playing':
|
if new['state'] == 'playing':
|
||||||
if 'lovelace' in (app_name := new['attributes']['app_name']).lower():
|
if 'lovelace' in (app_name := new['attributes']['app_name']).lower():
|
||||||
delay = timedelta(minutes=9, seconds=30)
|
delay = timedelta(minutes=9, seconds=30)
|
||||||
self.log(f'Recasting Lovelace in {delay}')
|
self.log(f'Recasting Lovelace in {delay}')
|
||||||
self.run_in(
|
self.run_in(
|
||||||
callback=lambda kwargs: self.tv_entity.turn_off(),
|
callback=lambda kwargs: self.media_entity.turn_off(),
|
||||||
delay=delay.total_seconds()
|
delay=delay.total_seconds()
|
||||||
)
|
)
|
||||||
self.run_in(
|
self.run_in(
|
||||||
@@ -63,12 +68,15 @@ class LivingRoomTV(Hass):
|
|||||||
'cast/show_lovelace_view',
|
'cast/show_lovelace_view',
|
||||||
view_path='tv',
|
view_path='tv',
|
||||||
dashboard_path='lovelace',
|
dashboard_path='lovelace',
|
||||||
entity_id=self.tv_entity.entity_id,
|
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):
|
||||||
# self.log(f'Cancelling scheduled callbacks')
|
|
||||||
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():
|
||||||
self.cancel_timer(handle)
|
self.cancel_timer(handle)
|
||||||
self.log(f'Cancelled {handle}')
|
self.log(f'Cancelled {handle}')
|
||||||
|
|
||||||
|
def hardware_off_callback(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
|
||||||
|
self.log('Hardware turned off')
|
||||||
|
self.media_entity.turn_off()
|
||||||
|
|||||||
Reference in New Issue
Block a user