Skip to content

Commit

Permalink
Merge pull request #14 from hostcc/feature/mqtt-object-id
Browse files Browse the repository at this point in the history
Predictable entity IDs
  • Loading branch information
hostcc authored Mar 13, 2023
2 parents a8c6501 + 46fb9f4 commit 1186a27
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/energomera_hass_mqtt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def hass_config_payload(self):
),
device_class=self._config_param.device_class,
unique_id=self._hass_unique_id,
object_id=self._hass_unique_id,
unit_of_measurement=self._config_param.unit,
state_class=self._config_param.state_class,
state_topic=self._hass_state_topic,
Expand Down Expand Up @@ -334,6 +335,7 @@ def hass_config_payload(self):
),
device_class=self._config_param.device_class,
unique_id=self._hass_unique_id,
object_id=self._hass_unique_id,
state_topic=self._hass_state_topic,
value_template='{{ value_json.value }}',
)
Expand Down
24 changes: 24 additions & 0 deletions tests/test_energomera.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
},
'device_class': 'energy',
'unique_id': 'CE301_00123456_ET0PE',
'object_id': 'CE301_00123456_ET0PE',
'unit_of_measurement': 'kWh',
'state_class': 'total_increasing',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -224,6 +225,7 @@
},
'device_class': 'energy',
'unique_id': 'CE301_00123456_ECMPE',
'object_id': 'CE301_00123456_ECMPE',
'unit_of_measurement': 'kWh',
'state_class': 'total',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -251,6 +253,7 @@
},
'device_class': 'energy',
'unique_id': 'CE301_00123456_ENMPE_PREV_MONTH',
'object_id': 'CE301_00123456_ENMPE_PREV_MONTH',
'unit_of_measurement': 'kWh',
'state_class': 'total_increasing',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -279,6 +282,7 @@
},
'device_class': 'energy',
'unique_id': 'CE301_00123456_ECMPE_PREV_MONTH',
'object_id': 'CE301_00123456_ECMPE_PREV_MONTH',
'unit_of_measurement': 'kWh',
'state_class': 'total',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -307,6 +311,7 @@
},
'device_class': 'energy',
'unique_id': 'CE301_00123456_ECDPE',
'object_id': 'CE301_00123456_ECDPE',
'unit_of_measurement': 'kWh',
'state_class': 'total',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -334,6 +339,7 @@
},
'device_class': 'power',
'unique_id': 'CE301_00123456_POWPP_0',
'object_id': 'CE301_00123456_POWPP_0',
'unit_of_measurement': 'kW',
'state_class': 'measurement',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -362,6 +368,7 @@
},
'device_class': 'power',
'unique_id': 'CE301_00123456_POWPP_1',
'object_id': 'CE301_00123456_POWPP_1',
'unit_of_measurement': 'kW',
'state_class': 'measurement',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -390,6 +397,7 @@
},
'device_class': 'power',
'unique_id': 'CE301_00123456_POWPP_2',
'object_id': 'CE301_00123456_POWPP_2',
'unit_of_measurement': 'kW',
'state_class': 'measurement',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -418,6 +426,7 @@
},
'device_class': 'power',
'unique_id': 'CE301_00123456_POWEP',
'object_id': 'CE301_00123456_POWEP',
'unit_of_measurement': 'kW',
'state_class': 'measurement',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -445,6 +454,7 @@
},
'device_class': 'voltage',
'unique_id': 'CE301_00123456_VOLTA_0',
'object_id': 'CE301_00123456_VOLTA_0',
'unit_of_measurement': 'V',
'state_class': 'measurement',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -473,6 +483,7 @@
},
'device_class': 'voltage',
'unique_id': 'CE301_00123456_VOLTA_1',
'object_id': 'CE301_00123456_VOLTA_1',
'unit_of_measurement': 'V',
'state_class': 'measurement',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -501,6 +512,7 @@
},
'device_class': 'voltage',
'unique_id': 'CE301_00123456_VOLTA_2',
'object_id': 'CE301_00123456_VOLTA_2',
'unit_of_measurement': 'V',
'state_class': 'measurement',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -529,6 +541,7 @@
},
'device_class': 'voltage',
'unique_id': 'CE301_00123456_VNULL',
'object_id': 'CE301_00123456_VNULL',
'unit_of_measurement': 'V',
'state_class': 'measurement',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -556,6 +569,7 @@
},
'device_class': 'current',
'unique_id': 'CE301_00123456_CURRE_0',
'object_id': 'CE301_00123456_CURRE_0',
'unit_of_measurement': 'A',
'state_class': 'measurement',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -584,6 +598,7 @@
},
'device_class': 'current',
'unique_id': 'CE301_00123456_CURRE_1',
'object_id': 'CE301_00123456_CURRE_1',
'unit_of_measurement': 'A',
'state_class': 'measurement',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -612,6 +627,7 @@
},
'device_class': 'current',
'unique_id': 'CE301_00123456_CURRE_2',
'object_id': 'CE301_00123456_CURRE_2',
'unit_of_measurement': 'A',
'state_class': 'measurement',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -640,6 +656,7 @@
},
'device_class': 'frequency',
'unique_id': 'CE301_00123456_FREQU',
'object_id': 'CE301_00123456_FREQU',
'unit_of_measurement': 'Hz',
'state_class': 'measurement',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -669,6 +686,7 @@
},
'device_class': 'current',
'unique_id': 'CE301_00123456_CURRE_INDEXED_0',
'object_id': 'CE301_00123456_CURRE_INDEXED_0',
'unit_of_measurement': 'A',
'state_class': 'measurement',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -697,6 +715,7 @@
},
'device_class': 'current',
'unique_id': 'CE301_00123456_CURRE_INDEXED_1',
'object_id': 'CE301_00123456_CURRE_INDEXED_1',
'unit_of_measurement': 'A',
'state_class': 'measurement',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -725,6 +744,7 @@
},
'device_class': 'current',
'unique_id': 'CE301_00123456_CURRE_INDEXED_2',
'object_id': 'CE301_00123456_CURRE_INDEXED_2',
'unit_of_measurement': 'A',
'state_class': 'measurement',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -754,6 +774,7 @@
},
'device_class': 'current',
'unique_id': 'CE301_00123456_CURRE_INDEXED_FALLBACK_0',
'object_id': 'CE301_00123456_CURRE_INDEXED_FALLBACK_0',
'unit_of_measurement': 'A',
'state_class': 'measurement',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -783,6 +804,7 @@
},
'device_class': 'current',
'unique_id': 'CE301_00123456_CURRE_INDEXED_FALLBACK_1',
'object_id': 'CE301_00123456_CURRE_INDEXED_FALLBACK_1',
'unit_of_measurement': 'A',
'state_class': 'measurement',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -812,6 +834,7 @@
},
'device_class': 'current',
'unique_id': 'CE301_00123456_CURRE_INDEXED_FALLBACK_2',
'object_id': 'CE301_00123456_CURRE_INDEXED_FALLBACK_2',
'unit_of_measurement': 'A',
'state_class': 'measurement',
'state_topic': 'homeassistant/sensor/CE301_00123456'
Expand Down Expand Up @@ -841,6 +864,7 @@
},
'device_class': 'connectivity',
'unique_id': 'CE301_00123456_IS_ONLINE',
'object_id': 'CE301_00123456_IS_ONLINE',
'state_topic': 'homeassistant/binary_sensor/CE301_00123456'
'/CE301_00123456_IS_ONLINE'
'/state',
Expand Down

0 comments on commit 1186a27

Please sign in to comment.