samsungtheframe now use create_entity to create its output sensor

This commit is contained in:
Pierre committed 2026-10-11 11:29:50 +02:00
1 parent b030645082
commit 40ce351fac
1 file changed
+23 -22
+23 -22
View File
@@ -23,12 +23,13 @@ class SamsungTheFrame(SmartObject):
self.power_plug = self.args['input_sensors']['power_plug']
self.power_plug_power = self.args['input_sensors']['power_plug_power']
self.is_on_sensor = self.args['output_sensors']['is_on']
self.is_art_mode_sensor = self.args['output_sensors']['is_art_mode']
self.tv_auto_shutdown = self.args['output_sensors']['tv_auto_shutdown']
if self.get_state(self.tv_auto_shutdown) == None:
self.set_state(self.tv_auto_shutdown,state = 'off')
self.is_on_entity = self.create_entity(self.args['output_sensors']['is_on'])
self.is_art_mode_entity = self.create_entity(self.args['output_sensors']['is_art_mode'])
auto_shutdown_state = self.get_state(self.args['output_sensors']['tv_auto_shutdown'])
self.tv_auto_shutdown_entity = self.create_entity(
self.args['output_sensors']['tv_auto_shutdown'],
state=auto_shutdown_state if auto_shutdown_state is not None else 'off',
)
if 'app_list' in self.args: self.app_list = self.args['app_list']
else: self.app_list = []
@@ -85,7 +86,7 @@ class SamsungTheFrame(SmartObject):
super().terminate()
def on_volume_event(self, event_name, event_data, direction):
if self.get_state(self.is_on_sensor) != 'on':
if self.is_on_entity.get_state() != 'on':
self.close_volume_connection()
return
try:
@@ -138,9 +139,9 @@ class SamsungTheFrame(SmartObject):
self.log_info(f"Requesting TV to switch to {requested_state}")
if requested_state == 'hdmi' and self.get_state(self.is_on_sensor) == 'off':
self.log_info(f"setting {self.tv_auto_shutdown} to 'on'")
self.set_state(self.tv_auto_shutdown,state = 'on')
if requested_state == 'hdmi' and self.is_on_entity.get_state() == 'off':
self.log_info(f"setting {self.tv_auto_shutdown_entity.entity_id} to 'on'")
self.tv_auto_shutdown_entity.set_state(state = 'on')
#if we already have a confirm callback, let's cancel it
if self.requested_state_confirm_cb_handle:
@@ -161,8 +162,8 @@ class SamsungTheFrame(SmartObject):
if not success:
self.requested_state_confirm_cb_handle = self.run_in(self.confirm_change_state_cb, wait_time)
return False
is_art_mode = self.get_state(self.is_art_mode_sensor) == 'on'
is_on = self.get_state(self.is_on_sensor) == 'on'
is_art_mode = self.is_art_mode_entity.get_state() == 'on'
is_on = self.is_on_entity.get_state() == 'on'
is_plugged = self.get_state(self.power_plug) == 'on'
if self.requested_state == 'tv_off':
@@ -267,7 +268,7 @@ class SamsungTheFrame(SmartObject):
# if result == SmartCondition.Result.Succeeded:
# self.request_tv_state('art_mode')
# else:
# if self.get_state(self.is_art_mode_sensor) == 'on':
# if self.is_art_mode_entity.get_state() == 'on':
# self.select_random_art()
# #I need to request state if I'm not in art_mode as it will cancel a potential request pending
# self.request_tv_state('off')
@@ -315,19 +316,19 @@ class SamsungTheFrame(SmartObject):
# self.log(f"update sensors failed with exception {exception_string}")
# return False , 5
if self.get_state(self.is_art_mode_sensor) != is_art_mode:
self.log_info(f"Updating sensor: {self.is_art_mode_sensor} = '{is_art_mode}'")
self.set_state(self.is_art_mode_sensor,state = is_art_mode)
if self.is_art_mode_entity.get_state() != is_art_mode:
self.log_info(f"Updating sensor: {self.is_art_mode_entity.entity_id} = '{is_art_mode}'")
self.is_art_mode_entity.set_state(state = is_art_mode)
if is_on == 'off':
self.close_volume_connection()
if self.get_state(self.is_on_sensor) != is_on:
self.log_info(f"Updating sensor: {self.is_on_sensor} = '{is_on}'")
self.set_state(self.is_on_sensor,state = is_on)
if is_on == 'off' and self.get_state(self.tv_auto_shutdown) != 'off':
self.log_info(f"setting {self.tv_auto_shutdown} to 'off'")
self.set_state(self.tv_auto_shutdown,state = 'off')
if self.is_on_entity.get_state() != is_on:
self.log_info(f"Updating sensor: {self.is_on_entity.entity_id} = '{is_on}'")
self.is_on_entity.set_state(state = is_on)
if is_on == 'off' and self.tv_auto_shutdown_entity.get_state() != 'off':
self.log_info(f"setting {self.tv_auto_shutdown_entity.entity_id} to 'off'")
self.tv_auto_shutdown_entity.set_state(state = 'off')
return True, 0