Add more parameters for DSMR sensor (#13967)

* Add more parameters for DSMR component

* Add suiting icon for power failure

* Add suiting icon for swells & sags

* Fix tab indentation -> spaces

* Fix too long lines (PEP8)
This commit is contained in:
Ruben 2018-05-01 20:40:48 +02:00 committed by Paulus Schoutsen
parent 9bc8f6649b
commit b00f771541

View File

@ -31,6 +31,8 @@ DOMAIN = 'dsmr'
ICON_GAS = 'mdi:fire'
ICON_POWER = 'mdi:flash'
ICON_POWER_FAILURE = 'mdi:flash-off'
ICON_SWELL_SAG = 'mdi:pulse'
# Smart meter sends telegram every 10 seconds
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=10)
@ -61,13 +63,86 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
# Define list of name,obis mappings to generate entities
obis_mapping = [
['Power Consumption', obis_ref.CURRENT_ELECTRICITY_USAGE],
['Power Production', obis_ref.CURRENT_ELECTRICITY_DELIVERY],
['Power Tariff', obis_ref.ELECTRICITY_ACTIVE_TARIFF],
['Power Consumption (low)', obis_ref.ELECTRICITY_USED_TARIFF_1],
['Power Consumption (normal)', obis_ref.ELECTRICITY_USED_TARIFF_2],
['Power Production (low)', obis_ref.ELECTRICITY_DELIVERED_TARIFF_1],
['Power Production (normal)', obis_ref.ELECTRICITY_DELIVERED_TARIFF_2],
[
'Power Consumption',
obis_ref.CURRENT_ELECTRICITY_USAGE
],
[
'Power Production',
obis_ref.CURRENT_ELECTRICITY_DELIVERY
],
[
'Power Tariff',
obis_ref.ELECTRICITY_ACTIVE_TARIFF
],
[
'Power Consumption (low)',
obis_ref.ELECTRICITY_USED_TARIFF_1
],
[
'Power Consumption (normal)',
obis_ref.ELECTRICITY_USED_TARIFF_2
],
[
'Power Production (low)',
obis_ref.ELECTRICITY_DELIVERED_TARIFF_1
],
[
'Power Production (normal)',
obis_ref.ELECTRICITY_DELIVERED_TARIFF_2
],
[
'Power Consumption Phase L1',
obis_ref.INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE
],
[
'Power Consumption Phase L2',
obis_ref.INSTANTANEOUS_ACTIVE_POWER_L2_POSITIVE
],
[
'Power Consumption Phase L3',
obis_ref.INSTANTANEOUS_ACTIVE_POWER_L3_POSITIVE
],
[
'Power Production Phase L1',
obis_ref.INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE
],
[
'Power Production Phase L2',
obis_ref.INSTANTANEOUS_ACTIVE_POWER_L2_NEGATIVE
],
[
'Power Production Phase L3',
obis_ref.INSTANTANEOUS_ACTIVE_POWER_L3_NEGATIVE
],
[
'Long Power Failure Count',
obis_ref.LONG_POWER_FAILURE_COUNT
],
[
'Voltage Sags Phase L1',
obis_ref.VOLTAGE_SAG_L1_COUNT
],
[
'Voltage Sags Phase L2',
obis_ref.VOLTAGE_SAG_L2_COUNT
],
[
'Voltage Sags Phase L3',
obis_ref.VOLTAGE_SAG_L3_COUNT
],
[
'Voltage Swells Phase L1',
obis_ref.VOLTAGE_SWELL_L1_COUNT
],
[
'Voltage Swells Phase L2',
obis_ref.VOLTAGE_SWELL_L2_COUNT
],
[
'Voltage Swells Phase L3',
obis_ref.VOLTAGE_SWELL_L3_COUNT
],
]
# Generate device entities
@ -174,6 +249,10 @@ class DSMREntity(Entity):
@property
def icon(self):
"""Icon to use in the frontend, if any."""
if 'Sags' in self._name or 'Swells' in self.name:
return ICON_SWELL_SAG
if 'Failure' in self._name:
return ICON_POWER_FAILURE
if 'Power' in self._name:
return ICON_POWER
elif 'Gas' in self._name: