From f938272253943723ec673b3b669841920d338681 Mon Sep 17 00:00:00 2001 From: davesmeghead Date: Sun, 4 Aug 2024 10:37:25 +0100 Subject: [PATCH] 0.9.6.12 - Bug fix for Panel Number Update --- custom_components/visonic/__init__.py | 16 ++++++++++++++++ custom_components/visonic/client.py | 2 +- custom_components/visonic/config_flow.py | 4 ++-- .../visonic/examples/complete_example.py | 12 +++++++----- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/custom_components/visonic/__init__.py b/custom_components/visonic/__init__.py index d48e10c..1899a1e 100644 --- a/custom_components/visonic/__init__.py +++ b/custom_components/visonic/__init__.py @@ -89,6 +89,8 @@ } ) +update_version_panel_number = 0 + # Create the types for the Configuration Parameter Entry VisonicConfigKey: HassEntryKey["VisonicConfigData"] = HassEntryKey(DOMAIN) type VisonicConfigEntry = ConfigEntry[VisonicConfigData] @@ -377,6 +379,20 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: VisonicConfigEn hass.config_entries.async_update_entry(config_entry, data=new, options=new, version=version) _LOGGER.debug(" Alarm Notification list set to default") + if version == 3: + version = 4 + new = config_entry.data.copy() + + if CONF_PANEL_NUMBER not in new: + # We have to assume that multiple panels will be updated at the same time, otherwise it gets complicated + _LOGGER.debug(f" Migrating Panel Number, using {update_version_panel_number}") + new[CONF_PANEL_NUMBER] = update_version_panel_number + update_version_panel_number = update_version_panel_number + 1 + else: + _LOGGER.debug(f" Panel Number already set to {new[CONF_PANEL_NUMBER]} so updating config version number only") + + hass.config_entries.async_update_entry(config_entry, data=new, options=new, version=version) + _LOGGER.info("Migration to version %s successful", config_entry.version) return True diff --git a/custom_components/visonic/client.py b/custom_components/visonic/client.py index 1f66c6a..996718f 100644 --- a/custom_components/visonic/client.py +++ b/custom_components/visonic/client.py @@ -122,7 +122,7 @@ # "trigger", #] -CLIENT_VERSION = "0.9.6.10" +CLIENT_VERSION = "0.9.6.12" MAX_CLIENT_LOG_ENTRIES = 300 diff --git a/custom_components/visonic/config_flow.py b/custom_components/visonic/config_flow.py index 0d90466..c8ef838 100644 --- a/custom_components/visonic/config_flow.py +++ b/custom_components/visonic/config_flow.py @@ -195,7 +195,7 @@ async def processcomplete(self): class VisonicConfigFlow(ConfigFlow, MyHandlers, domain=DOMAIN): """Handle a Visonic flow.""" - VERSION = 3 + VERSION = 4 CONNECTION_CLASS = CONN_CLASS_LOCAL_POLL def __init__(self): @@ -345,7 +345,7 @@ async def async_step_import(self, import_config): class VisonicOptionsFlowHandler(OptionsFlow, MyHandlers): """Handle options.""" - VERSION = 1 + VERSION = 4 CONNECTION_CLASS = CONN_CLASS_LOCAL_POLL def __init__(self, config_entry : ConfigEntry): diff --git a/custom_components/visonic/examples/complete_example.py b/custom_components/visonic/examples/complete_example.py index 12bf307..2990de6 100644 --- a/custom_components/visonic/examples/complete_example.py +++ b/custom_components/visonic/examples/complete_example.py @@ -18,6 +18,7 @@ from enum import Enum from pyvisonic import VisonicProtocol import socket +from inspect import currentframe, getframeinfo, stack # Try to import aconsole, if it fails then print an error message try: @@ -906,17 +907,18 @@ async def shutdown(loop, signal=None): await asyncio.gather(*tasks, return_exceptions=True) loop.stop() - - if __name__ == '__main__': + # Set up the asyncio first and then we don't get the debug data messages + testloop = asyncio.new_event_loop() + asyncio.set_event_loop(testloop) + testloop.set_exception_handler(handle_exception) + setupLocalLogger("ERROR", empty = True) # one of "WARNING" "INFO" "ERROR" "DEBUG" ConfigureLogger(str(args.print).lower(), None) setConnectionMode(str(args.connect).lower()) - testloop = asyncio.get_event_loop() - testloop.set_exception_handler(handle_exception) - client = VisonicClient(loop = testloop, config = myconfig) + if client is not None: success = True #client.connect(wait_sleep=False, wait_loop=True) if success: