Skip to content

Commit

Permalink
Merge pull request #26 from CyrilP/feature/conso
Browse files Browse the repository at this point in the history
Add energy sensors
  • Loading branch information
mrwiwi authored Mar 2, 2021
2 parents 6d940ce + 9ea94e7 commit 725c829
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
15 changes: 14 additions & 1 deletion sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ def __init__(self, elem_name, tydom_attributes_payload, attributes_topic_from_de
self.parent_device_id = str(tydom_attributes_payload['id'])
self.id = elem_name+'_tydom_'+str(tydom_attributes_payload['id'])
self.name = elem_name+'_tydom_'+'_'+str(tydom_attributes_payload['name']).replace(" ", "_")

if 'device_class' in tydom_attributes_payload.keys():
self.device_class = tydom_attributes_payload['device_class']

if 'unit_of_measurement' in tydom_attributes_payload.keys():
self.unit_of_measurement = tydom_attributes_payload['unit_of_measurement']

self.mqtt = mqtt


Expand Down Expand Up @@ -102,6 +107,14 @@ async def setup(self):
self.config = {}
self.config['name'] = self.name
self.config['unique_id'] = self.id
try:
self.config['device_class'] = self.device_class
except AttributeError:
pass
try:
self.config['unit_of_measurement'] = self.unit_of_measurement
except AttributeError:
pass
# self.config['device_class'] = self.device_class

#
Expand Down
52 changes: 48 additions & 4 deletions tydomMessagehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,33 @@

deviceBoilerKeywords = ['thermicLevel','delayThermicLevel','temperature','authorization','hvacMode','timeDelay','tempoOn','antifrostOn','openingDetected','presenceDetected','absence','loadSheddingOn','setpoint','delaySetpoint','anticipCoeff','outTemperature']

device_conso_classes = {'energyInstantTotElec': 'current', 'energyInstantTotElec_Min': 'current',
'energyInstantTotElec_Max': 'current',
'energyScaleTotElec_Min': 'current', 'energyScaleTotElec_Max': 'current',
'energyInstantTotElecP': 'power', 'energyInstantTotElec_P_Min': 'power',
'energyInstantTotElec_P_Max': 'power',
'energyScaleTotElec_P_Min': 'power', 'energyScaleTotElec_P_Max': 'power',
'energyInstantTi1P': 'power', 'energyInstantTi1P_Min': 'power', 'energyInstantTi1P_Max': 'power',
'energyScaleTi1P_Min': 'power',
'energyScaleTi1P_Max': 'power',
'energyInstantTi1I': 'current', 'energyInstantTi1I_Min': 'current',
'energyInstantTi1I_Max': 'current', 'energyScaleTi1I_Min': 'current',
'energyScaleTi1I_Max': 'current',
'energyTotIndexWatt': 'energy'}

device_conso_unit_of_measurement = {'energyInstantTotElec': 'A', 'energyInstantTotElec_Min': 'A', 'energyInstantTotElec_Max': 'A',
'energyScaleTotElec_Min': 'A', 'energyScaleTotElec_Max': 'A',
'energyInstantTotElecP': 'W', 'energyInstantTotElec_P_Min': 'W',
'energyInstantTotElec_P_Max': 'W',
'energyScaleTotElec_P_Min': 'W', 'energyScaleTotElec_P_Max': 'W',
'energyInstantTi1P': 'W', 'energyInstantTi1P_Min': 'W', 'energyInstantTi1P_Max': 'W',
'energyScaleTi1P_Min': 'W',
'energyScaleTi1P_Max': 'W',
'energyInstantTi1I': 'A', 'energyInstantTi1I_Min': 'A',
'energyInstantTi1I_Max': 'A', 'energyScaleTi1I_Min': 'A',
'energyScaleTi1I_Max': 'A', 'energyTotIndexWatt': 'Wh'}
device_conso_keywords = device_conso_classes.keys()

# Device dict for parsing
device_name = dict()
device_endpoint = dict()
Expand Down Expand Up @@ -243,10 +270,6 @@ async def parse_devices_data(self, parsed):
_LOGGER.debug("CURRENT ELEM={}".format(elem))
# endpoint_id = None

elementName = None
elementValue = None
elementValidity = None

# Element name
elementName = elem["name"]
# Element value
Expand Down Expand Up @@ -320,6 +343,27 @@ async def parse_devices_data(self, parsed):
attr_alarm['device_type'] = 'alarm_control_panel'
attr_alarm[elementName] = elementValue

if type_of_id == 'conso':
if elementName in device_conso_keywords and elementValidity == "upToDate":
attr_conso = {
'device_id': device_id,
'endpoint_id': endpoint_id,
'id': str(device_id) + '_' + str(endpoint_id),
'name': print_id,
'device_type': 'sensor',
elementName: elementValue
}

if elementName in device_conso_classes:
attr_conso['device_class'] = device_conso_classes[elementName]

if elementName in device_conso_unit_of_measurement:
attr_conso['unit_of_measurement'] = device_conso_unit_of_measurement[elementName]

new_conso = sensor(elem_name=elementName, tydom_attributes_payload=attr_conso,
attributes_topic_from_device='useless', mqtt=self.mqtt_client)
await new_conso.update()

except Exception as e:
print('msg_data error in parsing !')
print(e)
Expand Down

0 comments on commit 725c829

Please sign in to comment.