Skip to content

Commit

Permalink
parse cdata
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrilp committed Mar 21, 2024
1 parent 3f0af02 commit dcee07c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
12 changes: 11 additions & 1 deletion custom_components/deltadore_tydom/ha_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,26 @@ def get_sensors(self):
and value is not None
and attribute not in self._registered_sensors
):
if attribute in self.filtered_attrs:
alt_name = attribute.split('_')[0]
if attribute in self.filtered_attrs or alt_name in self.filtered_attrs:
continue
sensor_class = None
if attribute in self.sensor_classes:
sensor_class = self.sensor_classes[attribute]
elif alt_name in self.sensor_classes:
sensor_class = self.sensor_classes[alt_name]

state_class = None
if attribute in self.state_classes:
state_class = self.state_classes[attribute]
elif alt_name in self.state_classes:
state_class = self.state_classes[alt_name]

unit = None
if attribute in self.units:
unit = self.units[attribute]
elif alt_name in self.units:
unit = self.units[alt_name]

if isinstance(value, bool):
sensors.append(
Expand Down Expand Up @@ -374,6 +381,7 @@ class HAEnergy(SensorEntity, HAEntity):
"energyIndexHeatWatt": SensorDeviceClass.ENERGY,
"energyIndexECSWatt": SensorDeviceClass.ENERGY,
"energyIndexHeatGas": SensorDeviceClass.ENERGY,
"energyIndex": SensorDeviceClass.ENERGY,
"outTemperature": SensorDeviceClass.TEMPERATURE,
}

Expand All @@ -383,6 +391,7 @@ class HAEnergy(SensorEntity, HAEntity):
"energyIndexECSWatt": SensorStateClass.TOTAL_INCREASING,
"energyIndexHeatWatt": SensorStateClass.TOTAL_INCREASING,
"energyIndexHeatGas": SensorStateClass.TOTAL_INCREASING,
"energyIndex": SensorStateClass.TOTAL_INCREASING,
}

units = {
Expand Down Expand Up @@ -411,6 +420,7 @@ class HAEnergy(SensorEntity, HAEntity):
"energyIndexHeatWatt": UnitOfEnergy.WATT_HOUR,
"energyIndexECSWatt": UnitOfEnergy.WATT_HOUR,
"energyIndexHeatGas": UnitOfEnergy.WATT_HOUR,
"energyIndex": UnitOfEnergy.WATT_HOUR,
"outTemperature": UnitOfTemperature.CELSIUS,
}

Expand Down
50 changes: 49 additions & 1 deletion custom_components/deltadore_tydom/tydom/MessageHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,55 @@ async def parse_devices_data(self, parsed):

async def parse_devices_cdata(self, parsed):
"""Parse devices cdata."""
LOGGER.debug("parse_devices_data : %s", parsed)
LOGGER.debug("parse_devices_cdata : %s", parsed)
devices = []

for i in parsed:
for endpoint in i["endpoints"]:
if endpoint["error"] == 0 and len(endpoint["cdata"]) > 0:
try:
device_id = i["id"]
endpoint_id = endpoint["id"]
unique_id = str(endpoint_id) + "_" + str(device_id)
name_of_id = self.get_name_from_id(unique_id)
type_of_id = self.get_type_from_id(unique_id)

data = {}
for elem in endpoint["cdata"]:
if type_of_id == 'conso':

element_name = None
if elem["parameters"].get("dest"):
element_name = elem["name"] + "_" + elem["parameters"]["dest"]
else:
continue

element_value = elem["values"]["counter"]
data[element_name] = element_value

# Create the device
device = await MessageHandler.get_device(
self.tydom_client,
type_of_id,
unique_id,
device_id,
name_of_id,
endpoint_id,
data,
)
if device is not None:
devices.append(device)
LOGGER.debug(
"Device update (id=%s, endpoint=%s, name=%s, type=%s)",
device_id,
endpoint_id,
name_of_id,
type_of_id,
)

except Exception as e:
LOGGER.exception('Error when parsing msg_cdata')
return devices

# PUT response DIRTY parsing
def parse_put_response(self, bytes_str, start=6):
Expand Down

0 comments on commit dcee07c

Please sign in to comment.