Skip to content

Commit

Permalink
Logging cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
giachello committed Feb 5, 2023
1 parent df8dcda commit a775490
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 39 deletions.
8 changes: 4 additions & 4 deletions custom_components/mlgw/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
30 changes: 14 additions & 16 deletions custom_components/mlgw/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"),
Expand All @@ -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)
Expand Down
30 changes: 15 additions & 15 deletions custom_components/mlgw/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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):
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -261,15 +261,15 @@ 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
)
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)
Expand Down Expand Up @@ -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
Expand All @@ -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),
Expand All @@ -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."""
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/mlgw/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions custom_components/mlgw/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down

0 comments on commit a775490

Please sign in to comment.