Skip to content

Commit

Permalink
 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrilP committed Oct 31, 2023
1 parent 210a259 commit 80129c0
Showing 1 changed file with 0 additions and 99 deletions.
99 changes: 0 additions & 99 deletions custom_components/deltadore-tydom/tydom/MessageHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,105 +470,6 @@ async def parse_devices_data(self, parsed):
async def parse_devices_cdata(self, parsed):
"""Parse devices cdata."""
LOGGER.debug("parse_devices_data : %s", parsed)
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)
LOGGER.info(
"Device configured (id=%s, endpoint=%s, name=%s, type=%s)",
device_id,
endpoint_id,
name_of_id,
type_of_id,
)

for elem in endpoint["cdata"]:
if type_of_id == "conso":
if elem["name"] == "energyIndex":
device_class_of_id = "energy"
state_class_of_id = "total_increasing"
unit_of_measurement_of_id = "Wh"
element_name = elem["parameters"]["dest"]
element_index = "counter"

attr_conso = {
"device_id": device_id,
"endpoint_id": endpoint_id,
"id": unique_id,
"name": name_of_id,
"device_type": "sensor",
"device_class": device_class_of_id,
"state_class": state_class_of_id,
"unit_of_measurement": unit_of_measurement_of_id,
element_name: elem["values"][element_index],
}

# new_conso = Sensor(
# elem_name=element_name,
# tydom_attributes_payload=attr_conso,
# mqtt=self.mqtt_client,
# )
# await new_conso.update()

elif elem["name"] == "energyInstant":
device_class_of_id = "current"
state_class_of_id = "measurement"
unit_of_measurement_of_id = "VA"
element_name = elem["parameters"]["unit"]
element_index = "measure"

attr_conso = {
"device_id": device_id,
"endpoint_id": endpoint_id,
"id": unique_id,
"name": name_of_id,
"device_type": "sensor",
"device_class": device_class_of_id,
"state_class": state_class_of_id,
"unit_of_measurement": unit_of_measurement_of_id,
element_name: elem["values"][element_index],
}

# new_conso = Sensor(
# elem_name=element_name,
# tydom_attributes_payload=attr_conso,
# mqtt=self.mqtt_client,
# )
# await new_conso.update()

elif elem["name"] == "energyDistrib":
for elName in elem["values"]:
if elName != "date":
element_name = elName
element_index = elName
attr_conso = {
"device_id": device_id,
"endpoint_id": endpoint_id,
"id": unique_id,
"name": name_of_id,
"device_type": "sensor",
"device_class": "energy",
"state_class": "total_increasing",
"unit_of_measurement": "Wh",
element_name: elem["values"][
element_index
],
}

# new_conso = Sensor(
# elem_name=element_name,
# tydom_attributes_payload=attr_conso,
# mqtt=self.mqtt_client,
# )
# await new_conso.update()

except Exception as e:
LOGGER.error("Error when parsing msg_cdata (%s)", e)

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

0 comments on commit 80129c0

Please sign in to comment.