Skip to content

Commit

Permalink
feat: add raw_info to improve debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlb committed Jan 12, 2025
1 parent e34ef47 commit 05773f6
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/blueair_api/device_aws.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import dataclasses
import logging
from json import dumps

from .callbacks import CallbacksMixin
from .http_aws_blueair import HttpAwsBlueair
from .model_enum import ModelEnum
from . import intermediate_representation_aws as ir
from dataclasses import dataclass, field

_LOGGER = logging.getLogger(__name__)

type AttributeType[T] = T | None

@dataclasses.dataclass(slots=True)
@dataclass(slots=True)
class DeviceAws(CallbacksMixin):
@classmethod
async def create_device(cls, api, uuid, name, mac, type_name, refresh=False):
Expand All @@ -29,6 +29,8 @@ async def create_device(cls, api, uuid, name, mac, type_name, refresh=False):
return device_aws

api: HttpAwsBlueair
raw_info : dict[str: any] = field(repr=False, init=False)

uuid : str | None = None
name : str | None = None
name_api : str | None = None
Expand Down Expand Up @@ -66,14 +68,14 @@ async def create_device(cls, api, uuid, name, mac, type_name, refresh=False):

async def refresh(self):
_LOGGER.debug(f"refreshing blueair device aws: {self}")
info = await self.api.device_info(self.name_api, self.uuid)
_LOGGER.debug(dumps(info, indent=2))
self.raw_info = await self.api.device_info(self.name_api, self.uuid)
_LOGGER.debug(dumps(self.raw_info, indent=2))

# ir.parse_json(ir.Attribute, ir.query_json(info, "configuration.da"))
ds = ir.parse_json(ir.Sensor, ir.query_json(info, "configuration.ds"))
dc = ir.parse_json(ir.Control, ir.query_json(info, "configuration.dc"))
ds = ir.parse_json(ir.Sensor, ir.query_json(self.raw_info, "configuration.ds"))
dc = ir.parse_json(ir.Control, ir.query_json(self.raw_info, "configuration.dc"))

sensor_data = ir.SensorPack(info["sensordata"]).to_latest_value()
sensor_data = ir.SensorPack(self.raw_info["sensordata"]).to_latest_value()

def sensor_data_safe_get(key):
return sensor_data.get(key) if key in ds else NotImplemented
Expand All @@ -88,7 +90,7 @@ def sensor_data_safe_get(key):
def info_safe_get(path):
# directly reads for the schema. If the schema field is
# undefined, it is NotImplemented, not merely unavailable.
value = ir.query_json(info, path)
value = ir.query_json(self.raw_info, path)
if value is None:
return NotImplemented
return value
Expand All @@ -99,7 +101,7 @@ def info_safe_get(path):
self.serial_number = info_safe_get("configuration.di.ds")
self.sku = info_safe_get("configuration.di.sku")

states = ir.SensorPack(info["states"]).to_latest_value()
states = ir.SensorPack(self.raw_info["states"]).to_latest_value()

def states_safe_get(key):
return states.get(key) if key in dc else NotImplemented
Expand Down Expand Up @@ -185,4 +187,3 @@ def model(self) -> ModelEnum:
if self.sku == "112124":
return ModelEnum.T10I
return ModelEnum.UNKNOWN

0 comments on commit 05773f6

Please sign in to comment.