-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
24 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
from .const import DOMAIN | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
_Discovered_MLGW : dict = { } | ||
|
||
# Data schema for the configuration flows | ||
USER_STEP_DATA_SCHEMA = vol.Schema( | ||
|
@@ -59,24 +60,40 @@ def host_valid(host): | |
|
||
## Get serial number of mlgw | ||
|
||
# Get the MLGW/BLGW Serial number from the integrated Jabber Client | ||
# | ||
# This code causes the MLGW to crash if called too many times. Given that it is called every time there is | ||
# a zeroconf discovery (every few mins), after a week or so it causes the device to crash. So, we cache the | ||
# SN based on the host address. | ||
# | ||
# This is an undocumented feature of the MLGW. The Traffic looks like: | ||
# | ||
# # $ nc 192.168.1.10 5222 | ||
# <?xml version='1.0'?><stream:stream to='products.bang-olufsen.com' version='1.0' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'></stream:stream> | ||
# <stream:stream xmlns="jabber:client" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" from="[email protected]"> | ||
|
||
async def mlgw_get_xmpp_serial(_host: str) -> str: | ||
|
||
if _host in _Discovered_MLGW: | ||
_LOGGER.info("XMPP found cached sn") | ||
return _Discovered_MLGW[_host] | ||
|
||
_LOGGER.info("XMPP connect to MLGW: Open") | ||
# open socket to masterlink gateway | ||
_socket: socket.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
_socket.settimeout(TIMEOUT) | ||
try: | ||
_socket.connect((_host, 5222)) | ||
except Exception as e: | ||
_LOGGER.error("Error opening XMPP connection to MLGW (%s): %s" % (_host, e)) | ||
_LOGGER.error("Error opening XMPP to MLGW (%s): %s" % (_host, e)) | ||
_socket.close() | ||
return None | ||
# Request serial number to mlgw | ||
_telegram = ( | ||
"<?xml version='1.0'?>" | ||
"<stream:stream to='products.bang-olufsen.com' version='1.0' " | ||
"xmlns='jabber:client' " | ||
"xmlns:stream='http://etherx.jabber.org/streams'>" | ||
"xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>" | ||
"</stream:stream>" | ||
) | ||
## Receive serial number string from mlgw | ||
sn = None | ||
|
@@ -90,7 +107,9 @@ 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 connect to MLGW: SN %s" % (sn)) | ||
_LOGGER.info("XMPP got MLGW SN: %s" % (sn)) | ||
|
||
_Discovered_MLGW[_host] = sn | ||
|
||
return sn | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters