diff --git a/custom_components/nest_protect/__init__.py b/custom_components/nest_protect/__init__.py index 4ab33b5..280cd0b 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: 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