From 2181ab05300b9e76a1680062cf6c819cc9164919 Mon Sep 17 00:00:00 2001 From: GSzabados <35445496+GSzabados@users.noreply.github.com> Date: Tue, 26 Nov 2024 14:40:17 +0100 Subject: [PATCH 1/4] Trying to fix Errors in _async_subscribe_for_data #347 This would fix the issue with objects and then wraps it with Bucket as expected by the pynest client, but if it is still generating high traffic on Google servers, then there is a flaw somewhere in the main logic of subscription process, and it re-subscribes again and again with the pynest client, which I cannot really test, as I have only battery powered nest protects, so there isn't live motion detection. --- custom_components/nest_protect/__init__.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/custom_components/nest_protect/__init__.py b/custom_components/nest_protect/__init__.py index 4ab33b5..6e91400 100644 --- a/custom_components/nest_protect/__init__.py +++ b/custom_components/nest_protect/__init__.py @@ -206,10 +206,19 @@ async def _async_subscribe_for_data( LOGGER.debug(buckets) objects = [ - dict(b, **buckets.get(b.object_key, {})) for b in [data.updated_buckets] + dict(vars(b), **buckets.get(b.object_key, {})) for b in data.updated_buckets ] - data.updated_buckets = objects + data.updated_buckets = [ + Bucket( + object_key=bucket["object_key"], + object_revision=bucket["object_revision"], + object_timestamp=bucket["object_timestamp"], + value=bucket["value"], + type=bucket["type"] + ) + for bucket in objects + ] _register_subscribe_task(hass, entry, data) except ServerDisconnectedError: From 00822d2e3ea6297487aff412082a114b4450a1cc Mon Sep 17 00:00:00 2001 From: GSzabados <35445496+GSzabados@users.noreply.github.com> Date: Tue, 26 Nov 2024 14:43:47 +0100 Subject: [PATCH 2/4] Trying to fix Errors in _async_subscribe_for_data #347 Also needed to fix the aforementioned issue as wrapping with Bucket fails on the WhereBucketValue otherwise. --- custom_components/nest_protect/pynest/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/custom_components/nest_protect/pynest/models.py b/custom_components/nest_protect/pynest/models.py index 4e86323..5455942 100644 --- a/custom_components/nest_protect/pynest/models.py +++ b/custom_components/nest_protect/pynest/models.py @@ -85,7 +85,12 @@ def __post_init__(self): # if self.type == BucketType.TOPAZ: # self.value = TopazBucketValue(**self.value) if self.type == BucketType.WHERE: - self.value = WhereBucketValue(**self.value) + if isinstance(self.value, WhereBucketValue): + # It's already the correct type, no need to reinitialize + pass + else: + # Convert dictionary to WhereBucketValue instance + self.value = WhereBucketValue(**self.value) @dataclass From d87e3d210e896e3c5a27bd41ace8bacdd7a2e093 Mon Sep 17 00:00:00 2001 From: GSzabados <35445496+GSzabados@users.noreply.github.com> Date: Tue, 26 Nov 2024 15:13:11 +0100 Subject: [PATCH 3/4] Fix for lint --- custom_components/nest_protect/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/nest_protect/__init__.py b/custom_components/nest_protect/__init__.py index 6e91400..5f2caf6 100644 --- a/custom_components/nest_protect/__init__.py +++ b/custom_components/nest_protect/__init__.py @@ -216,8 +216,8 @@ async def _async_subscribe_for_data( object_timestamp=bucket["object_timestamp"], value=bucket["value"], type=bucket["type"] - ) - for bucket in objects + ) + for bucket in objects ] _register_subscribe_task(hass, entry, data) From b8bb3832f2fea087db636c1cd1d1d2bd8ec94004 Mon Sep 17 00:00:00 2001 From: GSzabados <35445496+GSzabados@users.noreply.github.com> Date: Tue, 26 Nov 2024 15:16:43 +0100 Subject: [PATCH 4/4] Another fix for lint --- custom_components/nest_protect/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/nest_protect/__init__.py b/custom_components/nest_protect/__init__.py index 5f2caf6..280cd0b 100644 --- a/custom_components/nest_protect/__init__.py +++ b/custom_components/nest_protect/__init__.py @@ -215,7 +215,7 @@ async def _async_subscribe_for_data( object_revision=bucket["object_revision"], object_timestamp=bucket["object_timestamp"], value=bucket["value"], - type=bucket["type"] + type=bucket["type"], ) for bucket in objects ]