From 5de3dac172a0d1abb65e152e5c3bb3bd4b13549c Mon Sep 17 00:00:00 2001 From: xNUTx Date: Thu, 5 Sep 2024 20:47:41 +0200 Subject: [PATCH 1/2] PR #140 seems to be a partial fix, so revisit to fix it again. --- custom_components/openhasp/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/openhasp/__init__.py b/custom_components/openhasp/__init__.py index 91e7f78..75213eb 100644 --- a/custom_components/openhasp/__init__.py +++ b/custom_components/openhasp/__init__.py @@ -556,7 +556,7 @@ async def async_change_page(self, page): if self._statusupdate: num_pages = self._statusupdate[HASP_NUM_PAGES] - if isinstance(page, int) and (page <= 0 or page > num_pages): + if isinstance(page, int) and isinstance(num_pages, int) and (page <= 0 or page > num_pages): _LOGGER.error( "Can't change to %s, available pages are 1 to %s", page, num_pages ) From d2c9afd3275ddc3b57b5cb6e4852f2f92d824afa Mon Sep 17 00:00:00 2001 From: xNUTx Date: Fri, 6 Sep 2024 10:40:36 +0200 Subject: [PATCH 2/2] Made sure the component setup is not done until MQTT is fully configured and started. This should also fix https://github.com/HASwitchPlate/openHASP-custom-component/issues/133 but needs testing by someone who had the MQTT error (I did not, I actually never have). --- custom_components/openhasp/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/custom_components/openhasp/__init__.py b/custom_components/openhasp/__init__.py index 75213eb..07af04b 100644 --- a/custom_components/openhasp/__init__.py +++ b/custom_components/openhasp/__init__.py @@ -7,6 +7,7 @@ import re from homeassistant.components.mqtt import async_subscribe, async_publish +import homeassistant.components.mqtt as mqtt from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN @@ -164,6 +165,9 @@ def hasp_object(value): async def async_setup(hass, config): + """Wait for MQTT to become available before starting.""" + await mqtt.async_wait_for_mqtt_client(hass) + """Set up the MQTT async example component.""" conf = config.get(DOMAIN)