diff --git a/apps/samsungtheframe.py b/apps/samsungtheframe.py index a71b5a7..9e3e058 100644 --- a/apps/samsungtheframe.py +++ b/apps/samsungtheframe.py @@ -15,7 +15,7 @@ class SamsungTheFrame(SmartObject): def on_initialize_smart_object(self): super().on_initialize_smart_object() - self.log(f"Initializing TheFrame with ip {self.args['ip_address']}") + self.log_info(f"Initializing TheFrame with ip {self.args['ip_address']}") #self.need_to_turn_off_when_hdmi_gone = False self.volume_connection = None self.requested_state = None @@ -98,7 +98,7 @@ class SamsungTheFrame(SmartObject): key_press_delay=0) except (OSError, tv_exceptions.ConnectionFailure, tv_exceptions.ResponseError, websocket.WebSocketException) as error: - self.log(f"Volume {direction} failed: {error}", level="WARNING") + self.log_info(f"Volume {direction} failed: {error}", level="WARNING") # Reconnect on the next press, without replaying a failed command. self.close_volume_connection() @@ -108,10 +108,10 @@ class SamsungTheFrame(SmartObject): def wake_up(self): if 'wake_up_service' in self.args: service = self.args['wake_up_service'] - self.log(f"Calling service {service}") + self.log_info(f"Calling service {service}") self.call_service(service) elif 'wol_switch' in self.args: - self.log(f"Switching on {self.args['wol_switch']}") + self.log_info(f"Switching on {self.args['wol_switch']}") self.turn_on(self.args['wol_switch']) if 'mac_address' in self.args: wakeonlan.send_magic_packet(self.args['mac_address']) @@ -128,23 +128,23 @@ class SamsungTheFrame(SmartObject): selected_art = random.choice(available_art) tv.art().select_image(selected_art['content_id'], show=True) except tv_exceptions.ResponseError as e: - self.log(f"select_random_art with exception ResponseError {e}") + self.log_info(f"select_random_art with exception ResponseError {e}") except TimeoutError: - self.log(f"select_random_art with exception TimeoutError") + self.log_info(f"select_random_art with exception TimeoutError") def request_tv_state(self,requested_state): valid_states = ['art_mode','tv_off','hdmi','power_off','manual'] assert requested_state in valid_states, f"{requested_state} is not a valid states. Valid states are {valid_states}" - self.log(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': - self.log(f"setting {self.tv_auto_shutdown} to 'on'") + self.log_info(f"setting {self.tv_auto_shutdown} to 'on'") self.set_state(self.tv_auto_shutdown,state = 'on') #if we already have a confirm callback, let's cancel it if self.requested_state_confirm_cb_handle: - self.log("Canceling previous confirm CB") + self.log_info("Canceling previous confirm CB") self.cancel_timer(self.requested_state_confirm_cb_handle) self.requested_state_confirm_cb_handle = None @@ -153,7 +153,7 @@ class SamsungTheFrame(SmartObject): else: self.requested_state = requested_state if self._process_state_request(): - self.log(f"The TV was already in the right state") + self.log_info(f"The TV was already in the right state") def _process_state_request(self): try: @@ -167,26 +167,26 @@ class SamsungTheFrame(SmartObject): if self.requested_state == 'tv_off': if not is_plugged: - self.log("Powering on TV") + self.log_info("Powering on TV") self.turn_on(self.power_plug) self.requested_state_confirm_cb_handle = self.run_in(self.confirm_change_state_cb, 60) return False elif is_on: tv = self.connect() - self.log("Switching to art mode") + self.log_info("Switching to art mode") tv.shortcuts().power() self.requested_state_confirm_cb_handle = self.run_in(self.confirm_change_state_cb, 10) return False elif is_art_mode: tv = self.connect() - self.log("Turning off TV") + self.log_info("Turning off TV") tv.hold_key('KEY_POWER',4) self.requested_state_confirm_cb_handle = self.run_in(self.confirm_change_state_cb, 10) return False elif self.requested_state == 'art_mode': if not is_art_mode: if not is_plugged: - self.log("Powering on TV") + self.log_info("Powering on TV") self.turn_on(self.power_plug) self.requested_state_confirm_cb_handle = self.run_in(self.confirm_change_state_cb, 60) return False @@ -204,18 +204,18 @@ class SamsungTheFrame(SmartObject): elif self.requested_state == "hdmi": if not is_plugged: - self.log("Powering on TV") + self.log_info("Powering on TV") self.turn_on(self.power_plug) self.requested_state_confirm_cb_handle = self.run_in(self.confirm_change_state_cb, 60) return False elif not self.has_power(): - self.log("Waking up TV") + self.log_info("Waking up TV") self.wake_up() self.requested_state_confirm_cb_handle = self.run_in(self.confirm_change_state_cb, 60) return False elif not is_on: tv = self.connect() - self.log("Turning on TV") + self.log_info("Turning on TV") tv.shortcuts().power() self.requested_state_confirm_cb_handle = self.run_in(self.confirm_change_state_cb, 5) return False @@ -225,8 +225,8 @@ class SamsungTheFrame(SmartObject): # {'id': '3201907018807', 'name': 'Netflix', 'running': True, 'version': '5.2.59020', 'visible': True} app_status = tv.rest_app_status(str(app)) if app_status['visible']: - self.log(f"{app_status['name']} is active") - self.log("Switching to Hdmi") + self.log_info(f"{app_status['name']} is active") + self.log_info("Switching to Hdmi") tv.send_key('KEY_HDMI') self.requested_state_confirm_cb_handle = self.run_in(self.confirm_change_state_cb, 5) return False @@ -240,14 +240,14 @@ class SamsungTheFrame(SmartObject): self.requested_state_confirm_cb_handle = self.run_in(self.confirm_change_state_cb, 10) return False elif not self.has_power(): - self.log("Waking up TV") + self.log_info("Waking up TV") self.wake_up() self.requested_state_confirm_cb_handle = self.run_in(self.confirm_change_state_cb, 60) return False elif is_art_mode: #it's better to turn off while it's art mode to ensure the TV will wake up in art mode and support properly wake on lan self.select_random_art() time.sleep(5) - self.log("Powering off TV") + self.log_info("Powering off TV") self.turn_off(self.power_plug) self.requested_state_confirm_cb_handle = self.run_in(self.confirm_change_state_cb, 5) return False @@ -290,23 +290,23 @@ class SamsungTheFrame(SmartObject): else: is_on = "on" except KeyError as e: #sometimes the lib throw an exception in File "/samsungtvws/art.py", line 318, in get_artmode - self.log(f"get_artmode() throw a KeyError Exception {e}") + self.log_info(f"get_artmode() throw a KeyError Exception {e}") return False , 10 except websocket.WebSocketConnectionClosedException: - self.log(f"update sensors failed with exception WebSocketConnectionClosedException") + self.log_info(f"update sensors failed with exception WebSocketConnectionClosedException") return False , 30 except ConnectionRefusedError: - self.log(f"update sensors failed with exception ConnectionRefusedError") + self.log_info(f"update sensors failed with exception ConnectionRefusedError") return False , 30 except tv_exceptions.ConnectionFailure: - self.log(f"update sensors failed with exception ConnectionFailure") + self.log_info(f"update sensors failed with exception ConnectionFailure") return False , 30 except OSError as error: - self.log(f"update sensors failed with exception OsError {error}") + self.log_info(f"update sensors failed with exception OsError {error}") return False , 30 except tv_exceptions.ResponseError as e: - self.log(f"update sensors failed with exception ResponseError {e}") + self.log_info(f"update sensors failed with exception ResponseError {e}") return False , 30 # except: # import traceback @@ -316,17 +316,17 @@ class SamsungTheFrame(SmartObject): # return False , 5 if self.get_state(self.is_art_mode_sensor) != is_art_mode: - self.log(f"Updating sensor: {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 is_on == 'off': self.close_volume_connection() if self.get_state(self.is_on_sensor) != is_on: - self.log(f"Updating sensor: {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(f"setting {self.tv_auto_shutdown} to 'off'") + self.log_info(f"setting {self.tv_auto_shutdown} to 'off'") self.set_state(self.tv_auto_shutdown,state = 'off')