Skip to content

Initial discovery of Gateways works fine, but when starting the integration with all gateways configured it can't find any gateway #26

@uschindler

Description

@uschindler

This is a followup when I applied the fix for #23:

Hi,
I tried to install the fork of @Iminet72. It install successfully and no python errors are happening. It detects the MobileAlerts Gateway successfully and adds the config for it. But when it then starts the integration it hangs repeating the same over and over (the first part of the log is printed with debugging enabled for the integration, so it successfully gets all information from the gateway and in CAN READ the configuration). But at end it can't enable the integration.

2024-10-19 15:55:36.154 DEBUG (MainThread) [custom_components.mobile_alerts.config_flow] async_step_single_gateway gateway MOBILEALERTS-Gateway V1.50, SerialNo: xxxx (id: xxxx)
Use DHCP: Yes
DHCP IP: 192.168.1.7
Fixed IP: 192.168.1.222
Fixed Netmask: 255.255.255.0
Fixed Gateway: 192.168.1.254
Fixed DNS: 192.168.1.253
Cloud Server: www.data199.com
Use Proxy: No
Proxy Server: 192.168.1.1
Proxy Port: 8080
Send data to cloud: Yes
Last Contact: Sat Oct 19 15:55:34 2024
2024-10-19 15:55:38.499 DEBUG (MainThread) [custom_components.mobile_alerts.config_flow] async_step_single_gateway gateway MOBILEALERTS-Gateway V1.50, SerialNo: xxxx(id: xxxxxx)
Use DHCP: Yes
DHCP IP: 192.168.1.7
Fixed IP: 192.168.1.222
Fixed Netmask: 255.255.255.0
Fixed Gateway: 192.168.1.254
Fixed DNS: 192.168.1.253
Cloud Server: www.data199.com
Use Proxy: No
Proxy Server: 192.168.1.1
Proxy Port: 8080
Send data to cloud: Yes
Last Contact: Sat Oct 19 15:55:34 2024
2024-10-19 15:55:38.500 DEBUG (MainThread) [custom_components.mobile_alerts] async_setup_entry {'created_at': '2024-10-19T13:55:38.499783+00:00', 'data': {'send_data_to_cloud': True}, 'disabled_by': None, 'domain': 'mobile_alerts', 'entry_id': '01JAJGZWC3CH0DMQ1ZKY7SW2T2', 'minor_version': 1, 'modified_at': '2024-10-19T13:55:38.499791+00:00', 'options': {}, 'pref_disable_new_entities': False, 'pref_disable_polling': False, 'source': 'user', 'title': 'xxxx', 'unique_id': 'xxxx', 'version': 1}
2024-10-19 15:56:13.863 DEBUG (MainThread) [custom_components.mobile_alerts] async_setup_entry {'created_at': '2024-10-19T13:55:38.499783+00:00', 'data': {'send_data_to_cloud': True}, 'disabled_by': None, 'domain': 'mobile_alerts', 'entry_id': '01JAJGZWC3CH0DMQ1ZKY7SW2T2', 'minor_version': 1, 'modified_at': '2024-10-19T13:55:38.499791+00:00', 'options': {}, 'pref_disable_new_entities': False, 'pref_disable_polling': False, 'source': 'user', 'title': 'xxxx', 'unique_id': 'xxxx', 'version': 1}
2024-10-19 15:56:54.379 DEBUG (MainThread) [custom_components.mobile_alerts] async_setup_entry {'created_at': '2024-10-19T13:55:38.499783+00:00', 'data': {'send_data_to_cloud': True}, 'disabled_by': None, 'domain': 'mobile_alerts', 'entry_id': '01JAJGZWC3CH0DMQ1ZKY7SW2T2', 'minor_version': 1, 'modified_at': '2024-10-19T13:55:38.499791+00:00', 'options': {}, 'pref_disable_new_entities': False, 'pref_disable_polling': False, 'source': 'user', 'title': 'xxxx', 'unique_id': 'xxxx', 'version': 1}
2024-10-19 15:57:44.668 DEBUG (MainThread) [custom_components.mobile_alerts] async_setup_entry {'created_at': '2024-10-19T13:55:38.499783+00:00', 'data': {'send_data_to_cloud': True}, 'disabled_by': None, 'domain': 'mobile_alerts', 'entry_id': '01JAJGZWC3CH0DMQ1ZKY7SW2T2', 'minor_version': 1, 'modified_at': '2024-10-19T13:55:38.499791+00:00', 'options': {}, 'pref_disable_new_entities': False, 'pref_disable_polling': False, 'source': 'user', 'title': 'xxxx', 'unique_id': 'xxxx', 'version': 1}
2024-10-19 15:58:55.096 DEBUG (MainThread) [custom_components.mobile_alerts] async_setup_entry {'created_at': '2024-10-19T13:55:38.499783+00:00', 'data': {'send_data_to_cloud': True}, 'disabled_by': None, 'domain': 'mobile_alerts', 'entry_id': '01JAJGZWC3CH0DMQ1ZKY7SW2T2', 'minor_version': 1, 'modified_at': '2024-10-19T13:55:38.499791+00:00', 'options': {}, 'pref_disable_new_entities': False, 'pref_disable_polling': False, 'source': 'user', 'title': 'xxxx', 'unique_id': 'xxxx', 'version': 1}
2024-10-19 16:00:45.376 DEBUG (MainThread) [custom_components.mobile_alerts] async_setup_entry {'created_at': '2024-10-19T13:55:38.499783+00:00', 'data': {'send_data_to_cloud': True}, 'disabled_by': None, 'domain': 'mobile_alerts', 'entry_id': '01JAJGZWC3CH0DMQ1ZKY7SW2T2', 'minor_version': 1, 'modified_at': '2024-10-19T13:55:38.499791+00:00', 'options': {}, 'pref_disable_new_entities': False, 'pref_disable_polling': False, 'source': 'user', 'title': 'xxxx', 'unique_id': 'xxxx', 'version': 1}
2024-10-19 16:02:35.572 DEBUG (MainThread) [custom_components.mobile_alerts] async_setup_entry {'created_at': '2024-10-19T13:55:38.499783+00:00', 'data': {'send_data_to_cloud': True}, 'disabled_by': None, 'domain': 'mobile_alerts', 'entry_id': '01JAJGZWC3CH0DMQ1ZKY7SW2T2', 'minor_version': 1, 'modified_at': '2024-10-19T13:55:38.499791+00:00', 'options': {}, 'pref_disable_new_entities': False, 'pref_disable_polling': False, 'source': 'user', 'title': 'xxxx', 'unique_id': 'xxxx', 'version': 1}

This repeats forever.

Unfortunately the Exception as printed in the UI (interestingly you can't find it in the log file its only printed on the integration configuration page) is not very helpful, it only says that it can't initialize the gateway. It is thrown here: https://github.com/Iminet72/ha_mobilealerts/blob/1d5a70b7f7da7e831ab3139ee82cd9adf430f1ef/custom_components/mobile_alerts/__init__.py#L30-L33

It returns false here in the low level gateway/proxy implementation causing the above exception: https://github.com/PlusPlus-ua/python-mobilealerts/blob/80b4591a3998dcbe62266e6f1294104b4ddeffd5/mobilealerts/gateway.py#L91-L100

I don't understand why the discovery of the gateway worked, but when it wants to enable the integration for the given gateway it fails while parsing the configuration.

The issue is simple:
My Hass server has multiple network interfaces and IP addresses. When the config workflow does the lookup it passes HASS IP as configured in the network interfaces as "base" address for the discovery (this is the one configured for broadcasts in the network settings of HASS). This IP address is retrieved from hass, see here:

gateways = []
ip_address = await async_get_source_ip(self.hass)
try:
gateways = await Gateway.discover(ip_address)
except socket.error as err:
_LOGGER.error("Gateways discovery error %r", err)

Unfortunately when the implementation starts it can't find the gateway and more (to set the proxy port and IP address) of proxy, because the broadcast is sent with None as source address. In case of multiple network interfaces, the system does not know what interface to use to send the broadcast for reconfiguring the gateway.

Basically, my quick hack was simple, just modify the main.py file and hardcode my internal IP address as 2nd parameter to new Gateway(). The correct fix is to move the proxy_ip a few lines below up:

    proxy_ip = await async_get_source_ip(hass, gateway_ip)

and use it for discovery. I have to figure out and check the networking stack of hass to use the correct address for broadcasting in both cases. Once the address of gateway is discovery.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions