From 591595bf5b3bca8065836a7884f5870da42922de Mon Sep 17 00:00:00 2001 From: jipem01 <46441154+jipem01@users.noreply.github.com> Date: Tue, 29 Oct 2024 00:20:19 +0100 Subject: [PATCH] Handle protocol deviation for early Linky Handle protocol deviation for early ADS. Currently ADS 67 only is concerned. 68 could also be concerned. Deviation : SINSTS -> SINST1 SMAXSN -> SMAXN, SAMXSN-1 -> SMAXMN-1 --- custom_components/linkytic/sensor.py | 114 +++++++++++++++++++-------- 1 file changed, 81 insertions(+), 33 deletions(-) diff --git a/custom_components/linkytic/sensor.py b/custom_components/linkytic/sensor.py index 844dbd2..01b9bf6 100644 --- a/custom_components/linkytic/sensor.py +++ b/custom_components/linkytic/sensor.py @@ -288,39 +288,6 @@ async def async_setup_entry( register_callback=True, conversion_function=(lambda x: x * 1000) # kVA conversion ), - RegularIntSensor( - tag="SINSTS", - name="Puissance app. instantanée soutirée", - config_title=config_entry.title, - config_uniq_id=config_entry.entry_id, - serial_reader=serial_reader, - device_class=SensorDeviceClass.APPARENT_POWER, - native_unit_of_measurement=UnitOfApparentPower.VOLT_AMPERE, - state_class=SensorStateClass.MEASUREMENT, - register_callback=True, - ), - RegularIntSensor( - tag="SMAXSN", - name="Puissance app. max. soutirée n", - config_title=config_entry.title, - config_uniq_id=config_entry.entry_id, - serial_reader=serial_reader, - device_class=SensorDeviceClass.APPARENT_POWER, - native_unit_of_measurement=UnitOfApparentPower.VOLT_AMPERE, - state_class=SensorStateClass.MEASUREMENT, - register_callback=True, - ), - RegularIntSensor( - tag="SMAXSN-1", - name="Puissance app. max. soutirée n-1", - config_title=config_entry.title, - config_uniq_id=config_entry.entry_id, - serial_reader=serial_reader, - device_class=SensorDeviceClass.APPARENT_POWER, - native_unit_of_measurement=UnitOfApparentPower.VOLT_AMPERE, - state_class=SensorStateClass.MEASUREMENT, - register_callback=True, - ), RegularIntSensor( tag="CCASN", name="Point n de la courbe de charge active soutirée", @@ -654,6 +621,87 @@ async def async_setup_entry( category=EntityCategory.DIAGNOSTIC, ), ] + # Handle protocol deviation for experimental/pilote modules + if (serial_reader.device_identification[DID_TYPE_CODE]=="67"): + sensors.append( + RegularIntSensor( + tag="SINST1", + name="Puissance app. instantanée soutirée", + config_title=config_entry.title, + config_uniq_id=config_entry.entry_id, + serial_reader=serial_reader, + device_class=SensorDeviceClass.APPARENT_POWER, + native_unit_of_measurement=UnitOfApparentPower.VOLT_AMPERE, + state_class=SensorStateClass.MEASUREMENT, + register_callback=True, + ) + ) + sensors.append( + RegularIntSensor( + tag="SMAXN", + name="Puissance app. max. soutirée n", + config_title=config_entry.title, + config_uniq_id=config_entry.entry_id, + serial_reader=serial_reader, + device_class=SensorDeviceClass.APPARENT_POWER, + native_unit_of_measurement=UnitOfApparentPower.VOLT_AMPERE, + state_class=SensorStateClass.MEASUREMENT, + register_callback=True, + ) + ) + sensors.append( + RegularIntSensor( + tag="SMAXN-1", + name="Puissance app. max. soutirée n-1", + config_title=config_entry.title, + config_uniq_id=config_entry.entry_id, + serial_reader=serial_reader, + device_class=SensorDeviceClass.APPARENT_POWER, + native_unit_of_measurement=UnitOfApparentPower.VOLT_AMPERE, + state_class=SensorStateClass.MEASUREMENT, + register_callback=True, + ) + ) + else: + sensors.append( + RegularIntSensor( + tag="SINSTS", + name="Puissance app. instantanée soutirée", + config_title=config_entry.title, + config_uniq_id=config_entry.entry_id, + serial_reader=serial_reader, + device_class=SensorDeviceClass.APPARENT_POWER, + native_unit_of_measurement=UnitOfApparentPower.VOLT_AMPERE, + state_class=SensorStateClass.MEASUREMENT, + register_callback=True, + ) + ) + sensors.append( + RegularIntSensor( + tag="SMAXSN", + name="Puissance app. max. soutirée n", + config_title=config_entry.title, + config_uniq_id=config_entry.entry_id, + serial_reader=serial_reader, + device_class=SensorDeviceClass.APPARENT_POWER, + native_unit_of_measurement=UnitOfApparentPower.VOLT_AMPERE, + state_class=SensorStateClass.MEASUREMENT, + register_callback=True, + ) + ) + sensors.append( + RegularIntSensor( + tag="SMAXSN-1", + name="Puissance app. max. soutirée n-1", + config_title=config_entry.title, + config_uniq_id=config_entry.entry_id, + serial_reader=serial_reader, + device_class=SensorDeviceClass.APPARENT_POWER, + native_unit_of_measurement=UnitOfApparentPower.VOLT_AMPERE, + state_class=SensorStateClass.MEASUREMENT, + register_callback=True, + ) + ) # Add producer specific sensors if bool(config_entry.data.get(SETUP_PRODUCER)): sensors.append(