From a775490b0400a6d42bc9a737c76a9d89aee9b0c3 Mon Sep 17 00:00:00 2001 From: Giovanni Iachello Date: Sun, 5 Feb 2023 09:01:36 -0800 Subject: [PATCH] Logging cleanup. --- custom_components/mlgw/config_flow.py | 8 +++---- custom_components/mlgw/const.py | 30 ++++++++++++-------------- custom_components/mlgw/gateway.py | 30 +++++++++++++------------- custom_components/mlgw/manifest.json | 2 +- custom_components/mlgw/media_player.py | 6 +++--- 5 files changed, 37 insertions(+), 39 deletions(-) diff --git a/custom_components/mlgw/config_flow.py b/custom_components/mlgw/config_flow.py index c5be313..b0ddfc5 100644 --- a/custom_components/mlgw/config_flow.py +++ b/custom_components/mlgw/config_flow.py @@ -75,10 +75,10 @@ def host_valid(host): async def mlgw_get_xmpp_serial(_host: str) -> str: if _host in _Discovered_MLGW: - _LOGGER.info("XMPP found cached sn") + _LOGGER.debug("XMPP found cached sn") return _Discovered_MLGW[_host] - _LOGGER.info("XMPP connect to MLGW: Open") + _LOGGER.debug("XMPP connect to MLGW: Open") # open socket to masterlink gateway _socket: socket.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) _socket.settimeout(TIMEOUT) @@ -107,7 +107,7 @@ async def mlgw_get_xmpp_serial(_host: str) -> str: _LOGGER.error("Error receiving MLGW info from %s: %s" % (_host, e)) _socket.close() - _LOGGER.info("XMPP got MLGW SN: %s" % (sn)) + _LOGGER.debug("XMPP got MLGW SN: %s" % (sn)) _Discovered_MLGW[_host] = sn @@ -139,7 +139,7 @@ def authenticate(self, user, password) -> bool: ) if response.status_code == 401: - _LOGGER.debug("Invalid authentication 401") + _LOGGER.warning("Invalid authentication to MLGW") raise InvalidAuth() if response.status_code != 200: diff --git a/custom_components/mlgw/const.py b/custom_components/mlgw/const.py index 0a31aa8..3f04c7c 100644 --- a/custom_components/mlgw/const.py +++ b/custom_components/mlgw/const.py @@ -73,12 +73,23 @@ ml_command_type_dict = dict( [ (0x04, "MASTER_PRESENT"), + # DISPLAY_SOURCE: Message sent with a payload showing the displayed source name. + # subtype 3 has the printable source name starting at byte 10 of the payload + (0x06, "DISPLAY_SOURCE"), + # START_VIDEO_DISTRIBUTION: Sent when a locally playing source starts being distributed on coaxial cable + (0x07, "START_VIDEO_DISTRIBUTION"), # REQUEST_DISTRIBUTED_SOURCE: seen when a device asks what source is being distributed # subtypes seen 01:request 04:no source 06:has source (byte 13 is source) (0x08, "REQUEST_DISTRIBUTED_SOURCE"), + # EXTENDED_SOURCE_INFORMATION: message with 6 subtypes showing information about the source. + # Printable info at byte 14 of the payload + # For Radio: 1: "" 2: Genre 3: Country 4: RDS info 5: Associated beo4 button 6: "Unknown" + # For A.Mem: 1: Genre 2: Album 3: Artist 4: Track name 5: Associated beo4 button 6: "Unknown" + (0x0B, "EXTENDED_SOURCE_INFORMATION"), + # BEO4_KEY fired when a key on the remote control is pressed (0x0D, "BEO4_KEY"), - (0x10, "STANDBY"), - (0x11, "RELEASE"), # when a device turns off + (0x10, "STANDBY"), # Fired when device requests to go in standby + (0x11, "RELEASE"), # Fired by a device that turns off (0x20, "MLGW_REMOTE_BEO4"), # REQUEST_LOCAL_SOURCE: Seen when a device asks what source is playing locally to a device # subtypes seen 02:request 04:no source 05:secondary source 06:primary source (byte 11 is source) @@ -87,9 +98,9 @@ (0x3C, "TIMER"), (0x40, "CLOCK"), (0x44, "TRACK_INFO"), + (0x45, "GOTO_SOURCE"), # fired when a device requests a source # LOCK_MANAGER_COMMAND: Lock to Determine what device issues source commands # reference: https://tidsskrift.dk/daimipb/article/download/7043/6004/0 - (0x45, "GOTO_SOURCE"), (0x5C, "LOCK_MANAGER_COMMAND"), (0x6C, "DISTRIBUTION_REQUEST"), (0x82, "TRACK_INFO_LONG"), @@ -99,19 +110,6 @@ # byte 22: 01: audio source 02: video source ff:undefined - byte 23: picture identifier (0x87, "STATUS_INFO"), (0x94, "VIDEO_TRACK_INFO"), - # - # ----------------------------------------------------------------------- - # More packets that we see on the bus, with a guess of the type - # DISPLAY_SOURCE: Message sent with a payload showing the displayed source name. - # subtype 3 has the printable source name starting at byte 10 of the payload - (0x06, "DISPLAY_SOURCE"), - # START_VIDEO_DISTRIBUTION: Sent when a locally playing source starts being distributed on coaxial cable - (0x07, "START_VIDEO_DISTRIBUTION"), - # EXTENDED_SOURCE_INFORMATION: message with 6 subtypes showing information about the source. - # Printable info at byte 14 of the payload - # For Radio: 1: "" 2: Genre 3: Country 4: RDS info 5: Associated beo4 button 6: "Unknown" - # For A.Mem: 1: Genre 2: Album 3: Artist 4: Track name 5: Associated beo4 button 6: "Unknown" - (0x0B, "EXTENDED_SOURCE_INFORMATION"), (0x96, "PC_PRESENT"), # PICTURE AND SOUND STATUS # byte 0: bit 0-1: sound status - bit 2-3: stereo mode (can be 0 in a 5.1 setup) diff --git a/custom_components/mlgw/gateway.py b/custom_components/mlgw/gateway.py index 2e456c4..9d00f9e 100644 --- a/custom_components/mlgw/gateway.py +++ b/custom_components/mlgw/gateway.py @@ -120,7 +120,7 @@ async def async_ml_connect(self): def ml_connect(self): """Connect the undocumented MasterLink stream.""" - _LOGGER.info("Attempt to connect to ML CLI: %s", self._host) + _LOGGER.debug("Attempt to connect to ML CLI: %s", self._host) self._connectedML = False try: @@ -156,7 +156,7 @@ def ml_connect(self): self._tn.write(b"_MLLOG ONLINE\r\n") self._connectedML = True - _LOGGER.info("Connected to ML CLI: %s", self._host) + _LOGGER.debug("Connected to ML CLI: %s", self._host) return True @@ -177,7 +177,7 @@ def ml_close(self): self._tn = None except OSError: _LOGGER.error("Error closing ML CLI") - _LOGGER.warning("Closed connection to ML CLI") + _LOGGER.debug("Closed connection to ML CLI") # This is the thread function to manage the ML CLI connection def ml_thread(self): @@ -207,7 +207,7 @@ def ml_thread(self): continue except KeyboardInterrupt: break - _LOGGER.info("Shutting down ML CLI thread") + _LOGGER.warning("Shutting down ML CLI thread") def ml_listen(self): """Receive notification about incoming event from the ML connection.""" @@ -261,7 +261,7 @@ def ml_listen(self): if encoded_telegram["payload_type"] == "GOTO_SOURCE": self._beolink_source = encoded_telegram["payload"]["source"] - _LOGGER.info("ML telegram: %s", encoded_telegram) + _LOGGER.info("ML: %s", encoded_telegram) self._hass.add_job( self._notify_incoming_ML_telegram, encoded_telegram @@ -269,7 +269,7 @@ def ml_listen(self): except ValueError: continue except IndexError: - _LOGGER.warning("ML CLI Thread: error parsing telegram: %s", line) + _LOGGER.error("ML CLI Thread: error parsing telegram: %s", line) continue else: # else sleep a bit and then continue reading # time.sleep(0.5) @@ -300,7 +300,7 @@ async def async_mlgw_connect(self): def mlgw_connect(self): """Open tcp connection to the mlgw API.""" - _LOGGER.info("Trying to connect to MLGW API") + _LOGGER.debug("Trying to connect to MLGW API") self._connectedMLGW = False # open socket to masterlink gateway @@ -316,7 +316,7 @@ def mlgw_connect(self): raise self._connectedMLGW = True - _LOGGER.info( + _LOGGER.debug( "MLGW API connection successful to %s port: %s", self._host, str(self._port), @@ -332,9 +332,9 @@ def mlgw_close(self): self._socket.close() self._socket = None except OSError: - _LOGGER.warning("Error closing connection to MLGW API") + _LOGGER.error("Error closing connection to MLGW API") return - _LOGGER.warning("Closed connection to MLGW API") + _LOGGER.debug("Closed connection to MLGW API") def mlgw_login(self): """Login to the gateway using username and password.""" @@ -459,7 +459,7 @@ def mlgw_thread(self): # after 10 attempts, or if HA asked to stop it, stop the thread self.mlgw_close() - _LOGGER.info("Shutting down MLGW API thread") + _LOGGER.warning("Shutting down MLGW API thread") def _mlgw_listen(self): """Listen and manage the MLGW connection""" @@ -598,7 +598,7 @@ def _mlgw_listen(self): virtual_action = _getvirtualactionstr(0x01) else: virtual_action = _getvirtualactionstr(response[5]) - _LOGGER.info( + _LOGGER.debug( "MLGW: Virtual button: %s %s", virtual_btn, virtual_action ) decoded = dict() @@ -609,12 +609,12 @@ def _mlgw_listen(self): elif msg_byte == 0x31: # Login Status if msg_payload == "FAIL": - _LOGGER.info( + _LOGGER.debug( "MLGW: MLGW protocol Password required to %s", self._host ) self.mlgw_login() elif msg_payload == "OK": - _LOGGER.info( + _LOGGER.debug( "MLGW: MLGW protocol Login successful to %s", self._host ) self.mlgw_get_serial() @@ -623,7 +623,7 @@ def _mlgw_listen(self): # _LOGGER.debug("mlgw: pong") elif msg_byte == 0x38: # Configuration changed notification - _LOGGER.debug("mlgw: configuration changed, reloading component") + _LOGGER.info("MLGW: configuration changed, reloading component") service_data = {"entry_id": self._config_entry_id} self._hass.services.call( "homeassistant", "reload_config_entry", service_data, False diff --git a/custom_components/mlgw/manifest.json b/custom_components/mlgw/manifest.json index cbb31b3..288f248 100644 --- a/custom_components/mlgw/manifest.json +++ b/custom_components/mlgw/manifest.json @@ -1,7 +1,7 @@ { "domain": "mlgw", "name": "MasterLink Gateway", - "version" : "2023.2.2", + "version" : "2023.2.3", "config_flow": true, "documentation": "https://github.com/giachello/mlgw", "issue_tracker": "https://github.com/giachello/mlgw/issues", diff --git a/custom_components/mlgw/media_player.py b/custom_components/mlgw/media_player.py index d057bba..da67321 100644 --- a/custom_components/mlgw/media_player.py +++ b/custom_components/mlgw/media_player.py @@ -267,15 +267,15 @@ def _beospeaker_message_listener(_event: Event): # I am telling the system I am turning off if _event.data["payload_type"] == "RELEASE": - _LOGGER.info("ML LOG said: RELEASE id %s", self._ml) + _LOGGER.debug("ML: RELEASE id %s", self._ml) self._pwon = False self._playing = False self.clear_media_info() # I am telling the system I want a source elif _event.data["payload_type"] == "GOTO_SOURCE": - _LOGGER.info( - "ML LOG said: GOTO_SOURCE %s on device %s", + _LOGGER.debug( + "ML: GOTO_SOURCE %s on device %s", _event.data["payload"]["source"], self._ml, )