Skip to content

Commit

Permalink
Fixed issue with cached data being fetched from the API
Browse files Browse the repository at this point in the history
  • Loading branch information
sockless-coding committed Sep 24, 2024
1 parent a656895 commit 3b42c46
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
4 changes: 4 additions & 0 deletions custom_components/panasonic_cc/pcomfortcloud/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ class IAutoXMode(Enum):
Off = 1
On = 2

class StatusDataMode(Enum):
LIVE = 0
CACHED = 1

INVALID_TEMPERATURE = 126

DEFAULT_X_APP_VERSION = "1.21.0"
Expand Down
15 changes: 14 additions & 1 deletion custom_components/panasonic_cc/pcomfortcloud/panasonicdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def read_enum(json, key, type, default_value):
try:
return type(json[key])
except Exception as es:
_LOGGER.warn("Error reading property '%s' with value '%s'", key, json[key], exc_info= es)
_LOGGER.warning("Error reading property '%s' with value '%s'", key, json[key], exc_info= es)
return default_value

def read_value(json, key, default_value):
Expand All @@ -34,6 +34,7 @@ def __init__(self, json = None) -> None:
self.model = ''
self._has_parameters = False
self._raw = None
self._status_data_mode = constants.StatusDataMode.LIVE
self.load(json)


Expand All @@ -58,6 +59,12 @@ def is_valid(self):
@property
def raw(self):
return self._raw

@property
def status_data_mode(self):
return self._status_data_mode




class PanasonicDevice:
Expand All @@ -66,11 +73,16 @@ def __init__(self, info: PanasonicDeviceInfo, json = None) -> None:
self._features: PanasonicDeviceFeatures = None
self._parameters: PanasonicDeviceParameters = None
self._last_update = datetime.now(timezone.utc)
self._timestamp: datetime = None
self.load(json)

@property
def id(self)->str:
return self.info.id

@property
def timestamp(self)->datetime:
return self._timestamp

@property
def info(self) -> PanasonicDeviceInfo:
Expand Down Expand Up @@ -150,6 +162,7 @@ def load(self, json) -> bool:
has_changed = True if self._parameters.load(json_parameters) else has_changed
if has_changed:
self._last_update = datetime.now(timezone.utc)
self._timestamp = datetime.fromtimestamp(json['timestamp'] / 1000, timezone.utc)
return has_changed


Expand Down
14 changes: 14 additions & 0 deletions custom_components/panasonic_cc/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ class PanasonicEnergySensorEntityDescription(SensorEntityDescription):
is_available=lambda device: True,
entity_registry_enabled_default=False,
)
DATA_AGE_DESCRIPTION = PanasonicSensorEntityDescription(
key="data_age",
translation_key="data_age",
name="Data Age",
icon="mdi:clock-outline",
device_class=SensorDeviceClass.TIMESTAMP,
entity_category=EntityCategory.DIAGNOSTIC,
state_class=None,
native_unit_of_measurement=None,
get_state=lambda device: device.timestamp,
is_available=lambda device: True,
entity_registry_enabled_default=True,
)
DAILY_ENERGY_DESCRIPTION = PanasonicEnergySensorEntityDescription(
key="daily_energy_sensor",
translation_key="daily_energy_sensor",
Expand Down Expand Up @@ -151,6 +164,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
entities.append(PanasonicSensorEntity(coordinator, INSIDE_TEMPERATURE_DESCRIPTION))
entities.append(PanasonicSensorEntity(coordinator, OUTSIDE_TEMPERATURE_DESCRIPTION))
entities.append(PanasonicSensorEntity(coordinator, LAST_UPDATE_TIME_DESCRIPTION))
entities.append(PanasonicSensorEntity(coordinator, DATA_AGE_DESCRIPTION))
if coordinator.device.has_zones:
for zone in coordinator.device.parameters.zones:
entities.append(PanasonicSensorEntity(
Expand Down

0 comments on commit 3b42c46

Please sign in to comment.