Untitled
@classmethod def format_meter_node(cls, meter_node: Dict[str, Any]) -> DeviceEntry: """ Class method to create a Modbus entry from a controller node obtained in FIT. Throws a Key Error if any of the required fields are not present in the FIT node. @param meter_node: FIT Node of type "meter" @type meter_node: dict @return: Modbus Entry representation the FIT node @rtype: ModbusEntry """ try: meter_properties = meter_node[MeterNode.PROPERTIES] meter_info = meter_node[MeterNode.METER_INFO] return cls( device_id=meter_node[MeterNode.ID], device_name=meter_properties.get(MeterNode.NAME, ""), ip_address=meter_properties[MeterNode.IP_ADDRESS], port=meter_properties.get(MeterNode.PORT, MODBUS_DEFAULT_PORT), active=meter_properties[MeterNode.POLLING] == "true", protocol=meter_info[MeterNode.PROTOCOL], polling_method=PollingMethods.TEMPLATE, polling_template=meter_info[MeterNode.TEMPLATE], transformation_method=PollingMethods.TEMPLATE, transformation_template=meter_info[MeterNode.TEMPLATE], unit_id=meter_properties[MeterNode.UNIT_ID], model=meter_properties.get(MeterNode.MODEL), manufacturer=meter_properties.get(MeterNode.MANUFACTURER), fit_v1_id=meter_properties.get(MeterNode.FIT_V1_ID), ) except KeyError: logger.debug( f"There is a malformed FIT entry {meter_node[MeterNode.ID]}, " f"missing one of the basic fields (id, meter info, properties)" ) raise
Leave a Comment