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