Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions homeassistant/components/sensor/dsmr.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@

CONF_DSMR_VERSION = 'dsmr_version'
CONF_RECONNECT_INTERVAL = 'reconnect_interval'
CONF_PRECISION = 'precision'

DEFAULT_DSMR_VERSION = '2.2'
DEFAULT_PORT = '/dev/ttyUSB0'
DEFAULT_PRECISION = 3

DOMAIN = 'dsmr'

ICON_GAS = 'mdi:fire'
Expand All @@ -45,6 +48,7 @@
vol.Optional(CONF_DSMR_VERSION, default=DEFAULT_DSMR_VERSION): vol.All(
cv.string, vol.In(['5', '4', '2.2'])),
vol.Optional(CONF_RECONNECT_INTERVAL, default=30): int,
vol.Optional(CONF_PRECISION, default=DEFAULT_PRECISION): vol.Coerce(int),
})


Expand Down Expand Up @@ -146,7 +150,7 @@ async def async_setup_platform(hass, config, async_add_entities,
]

# Generate device entities
devices = [DSMREntity(name, obis) for name, obis in obis_mapping]
devices = [DSMREntity(name, obis, config) for name, obis in obis_mapping]

# Protocol version specific obis
if dsmr_version in ('4', '5'):
Expand All @@ -156,8 +160,8 @@ async def async_setup_platform(hass, config, async_add_entities,

# Add gas meter reading and derivative for usage
devices += [
DSMREntity('Gas Consumption', gas_obis),
DerivativeDSMREntity('Hourly Gas Consumption', gas_obis),
DSMREntity('Gas Consumption', gas_obis, config),
DerivativeDSMREntity('Hourly Gas Consumption', gas_obis, config),
]

async_add_entities(devices)
Expand Down Expand Up @@ -224,10 +228,11 @@ async def connect_and_reconnect():
class DSMREntity(Entity):
"""Entity reading values from DSMR telegram."""

def __init__(self, name, obis):
def __init__(self, name, obis, config):
"""Initialize entity."""
self._name = name
self._obis = obis
self._config = config
self.telegram = {}

def get_dsmr_object_attr(self, attribute):
Expand Down Expand Up @@ -267,6 +272,11 @@ def state(self):
if self._obis == obis.ELECTRICITY_ACTIVE_TARIFF:
return self.translate_tariff(value)

try:
value = round(float(value),self._config[CONF_PRECISION])
Comment thread
zumitnl marked this conversation as resolved.
Outdated
except:
Comment thread
zumitnl marked this conversation as resolved.
Outdated
value = value
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated

if value is not None:
return value

Expand Down