sonoscontroller now use create_entity to create its output sensor
This commit is contained in:
1 parent
79dd13f31d
commit
b030645082
1 file changed
+9
-10
+9
-10
@@ -159,10 +159,9 @@ class SonosPlayer:
|
|||||||
self.log(f"Creating a ValueSelector for the audio_delay")
|
self.log(f"Creating a ValueSelector for the audio_delay")
|
||||||
self.audio_delay_selector = ValueSelector(self.controller,self.controller,sensor_name = yaml_conf["audio_delay"]["entity"],super_entity_id = self.entity_id,yaml_block = yaml_conf["audio_delay"]['value'],self_initialize = True)
|
self.audio_delay_selector = ValueSelector(self.controller,self.controller,sensor_name = yaml_conf["audio_delay"]["entity"],super_entity_id = self.entity_id,yaml_block = yaml_conf["audio_delay"]['value'],self_initialize = True)
|
||||||
|
|
||||||
self.is_playing_podcast_sensor = f'binary_sensor.{player_name}_is_playing_podcast'
|
self.is_playing_podcast_entity = self.controller.create_entity(
|
||||||
is_playing_podcast_sensor_entity = self.controller.get_entity(self.is_playing_podcast_sensor)
|
f'binary_sensor.{player_name}_is_playing_podcast',
|
||||||
if not is_playing_podcast_sensor_entity.exists():
|
)
|
||||||
is_playing_podcast_sensor_entity.add()
|
|
||||||
self.controller.listen_state(self.on_state_change,self.entity_id)
|
self.controller.listen_state(self.on_state_change,self.entity_id)
|
||||||
self.controller.listen_state(self.on_update_media_artist,self.entity_id,attribute = "media_artist")
|
self.controller.listen_state(self.on_update_media_artist,self.entity_id,attribute = "media_artist")
|
||||||
self.update_is_playing_podcast_sensor()
|
self.update_is_playing_podcast_sensor()
|
||||||
@@ -401,16 +400,16 @@ class SonosPlayer:
|
|||||||
self.update_is_playing_podcast_sensor()
|
self.update_is_playing_podcast_sensor()
|
||||||
|
|
||||||
def update_is_playing_podcast_sensor(self):
|
def update_is_playing_podcast_sensor(self):
|
||||||
if self.is_playing_podcast_sensor and self.is_playing():
|
if self.is_playing_podcast_entity and self.is_playing():
|
||||||
prev_state = self.controller.get_state(self.is_playing_podcast_sensor)
|
prev_state = self.is_playing_podcast_entity.get_state()
|
||||||
if self.controller.get_state(self.entity_id,attribute = "media_artist") == None:
|
if self.controller.get_state(self.entity_id,attribute = "media_artist") == None:
|
||||||
if prev_state != 'on':
|
if prev_state != 'on':
|
||||||
self.log(f"setting {self.is_playing_podcast_sensor} to on")
|
self.log(f"setting {self.is_playing_podcast_entity.entity_id} to on")
|
||||||
self.controller.set_state(self.is_playing_podcast_sensor,state = "on")
|
self.is_playing_podcast_entity.set_state(state = "on")
|
||||||
else:
|
else:
|
||||||
if prev_state != 'off':
|
if prev_state != 'off':
|
||||||
self.log(f"setting {self.is_playing_podcast_sensor} to off")
|
self.log(f"setting {self.is_playing_podcast_entity.entity_id} to off")
|
||||||
self.controller.set_state(self.is_playing_podcast_sensor,state = "off")
|
self.is_playing_podcast_entity.set_state(state = "off")
|
||||||
|
|
||||||
def on_update_off_conditions(self):
|
def on_update_off_conditions(self):
|
||||||
if self.off_conditions_evaluator.evaluate(False) == SmartCondition.Result.Succeeded:
|
if self.off_conditions_evaluator.evaluate(False) == SmartCondition.Result.Succeeded:
|
||||||
|
|||||||
Reference in new issue
Block a user