From 191d10e8521465cad93ae818a94e6d2fef8936b5 Mon Sep 17 00:00:00 2001 From: Pierre-Luc Milord <46912935+plmilord@users.noreply.github.com> Date: Sat, 15 Jan 2022 14:56:11 -0500 Subject: [PATCH] Minimized the loading time Minimized the loading time of this component. More decent values now (~1s on docker; ~35s on RPi3)! --- README.md | 2 +- custom_components/spaclient/__init__.py | 4 ++-- custom_components/spaclient/spaclient.py | 16 +++++----------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 07fd49e..dfd1421 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Time sync with Home Assistant | ✓ - [x] Allow the installation of this custom component through the Home Assistant integrations menu (use of config_flow.py) - [ ] Allow the installation of this custom component through HACS - [ ] Bring back the ability to configure this custom component via the entries in configuration.yaml -- [ ] Investigate why it takes so long to load the component on an RPi (~2s on docker; ~85s on RPi3) +- [x] Investigate why it takes so long to load the component on an RPi (~2s on docker; ~85s on RPi3) - [ ] Add programming capability for filter cycles - [ ] Change the way I update entities (from polling mode to subscribing to updates) - [ ] Customize entity IDs with **Spa Client** custom name to allow multiple integrations in the same Home Assistant instance diff --git a/custom_components/spaclient/__init__.py b/custom_components/spaclient/__init__.py index c507c12..182185a 100644 --- a/custom_components/spaclient/__init__.py +++ b/custom_components/spaclient/__init__.py @@ -79,10 +79,10 @@ async def async_setup_entry(hass, config_entry): hass.loop.create_task(spa.read_all_msg()) hass.loop.create_task(spa.keep_alive_call()) - spa.print_variables() - for component in SPACLIENT_COMPONENTS: hass.async_create_task(hass.config_entries.async_forward_entry_setup(config_entry, component)) + + spa.print_variables() return True diff --git a/custom_components/spaclient/spaclient.py b/custom_components/spaclient/spaclient.py index 7c87c67..2149baf 100644 --- a/custom_components/spaclient/spaclient.py +++ b/custom_components/spaclient/spaclient.py @@ -708,7 +708,6 @@ def send_message(self, type, payload): message = prefix + bytes([length]) + type + payload + bytes([checksum]) + prefix try: - #_LOGGER.info("send_message : %s", message) #Validation point self.s.send(message) except IOError as e: #_LOGGER.info("send_message - IOError = %s", e) #Validation point @@ -716,9 +715,8 @@ def send_message(self, type, payload): self.get_socket() async def send_module_identification_request(self): + self.send_message(b'\x0a\xbf\x04', bytes([])) while self.module_identification_loaded == False: - self.send_message(b'\x0a\xbf\x04', bytes([])) - await asyncio.sleep(.1) self.read_msg() async def keep_alive_call(self): @@ -743,27 +741,23 @@ async def set_current_time(self): self.send_message(b'\x0a\xbf\x21', bytes([now.hour]) + bytes([now.minute])) async def send_configuration_request(self): + self.send_message(b'\x0a\xbf\x22', b'\x00' + b'\x00' + b'\x01') while self.configuration_loaded == False: - self.send_message(b'\x0a\xbf\x22', b'\x00' + b'\x00' + b'\x01') - await asyncio.sleep(.1) self.read_msg() async def send_filter_cycles_request(self): + self.send_message(b'\x0a\xbf\x22', b'\x01' + b'\x00' + b'\x00') while self.filter_cycles_loaded == False: - self.send_message(b'\x0a\xbf\x22', b'\x01' + b'\x00' + b'\x00') - await asyncio.sleep(.1) self.read_msg() async def send_information_request(self): + self.send_message(b'\x0a\xbf\x22', b'\x02' + b'\x00' + b'\x00') while self.information_loaded == False: - self.send_message(b'\x0a\xbf\x22', b'\x02' + b'\x00' + b'\x00') - await asyncio.sleep(.1) self.read_msg() async def send_additional_information_request(self): + self.send_message(b'\x0a\xbf\x22', b'\x04' + b'\x00' + b'\x00') while self.additional_information_loaded == False: - self.send_message(b'\x0a\xbf\x22', b'\x04' + b'\x00' + b'\x00') - await asyncio.sleep(.1) self.read_msg() def send_preferences_request(self): #Not use yet!