8000 DSMR: Device/state classes, icons, less common disabled by default by frenck · Pull Request #52159 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

DSMR: Device/state classes, icons, less common disabled by default #52159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
105 changes: 96 additions & 9 deletions homeassistant/components/dsmr/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@

from dsmr_parser import obis_references

from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT
from homeassistant.const import (
DEVICE_CLASS_CURRENT,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_POWER,
DEVICE_CLASS_VOLTAGE,
)
from homeassistant.util import dt

from .models import DSMRSensor

DOMAIN = "dsmr"
Expand Down Expand Up @@ -33,164 +42,242 @@
DEVICE_NAME_ENERGY = "Energy Meter"
DEVICE_NAME_GAS = "Gas Meter"

ICON_GAS = "mdi:fire"
ICON_POWER = "mdi:flash"
ICON_POWER_FAILURE = "mdi:flash-off"
ICON_SWELL_SAG = "mdi:pulse"


SENSORS: list[DSMRSensor] = [
DSMRSensor(
name="Power Consumption",
obis_reference=obis_references.CURRENT_ELECTRICITY_USAGE,
device_class=DEVICE_CLASS_POWER,
force_update=True,
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Power Production",
obis_reference=obis_references.CURRENT_ELECTRICITY_DELIVERY,
device_class=DEVICE_CLASS_POWER,
force_update=True,
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Power Tariff",
obis_reference=obis_references.ELECTRICITY_ACTIVE_TARIFF,
icon="mdi:flash",
),
DSMRSensor(
name="Energy Consumption (tarif 1)",
obis_reference=obis_references.ELECTRICITY_USED_TARIFF_1,
device_class=DEVICE_CLASS_ENERGY,
force_update=True,
last_reset=dt.utc_from_timestamp(0),
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Energy Consumption (tarif 2)",
obis_reference=obis_references.ELECTRICITY_USED_TARIFF_2,
force_update=True,
device_class=DEVICE_CLASS_ENERGY,
last_reset=dt.utc_from_timestamp(0),
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Energy Production (tarif 1)",
obis_reference=obis_references.ELECTRICITY_DELIVERED_TARIFF_1,
force_update=True,
device_class=DEVICE_CLASS_ENERGY,
last_reset=dt.utc_from_timestamp(0),
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Energy Production (tarif 2)",
obis_reference=obis_references.ELECTRICITY_DELIVERED_TARIFF_2,
force_update=True,
10000 device_class=DEVICE_CLASS_ENERGY,
last_reset=dt.utc_from_timestamp(0),
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Power Consumption Phase L1",
obis_reference=obis_references.INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE,
device_class=DEVICE_CLASS_POWER,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Power Consumption Phase L2",
obis_reference=obis_references.INSTANTANEOUS_ACTIVE_POWER_L2_POSITIVE,
device_class=DEVICE_CLASS_POWER,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Power Consumption Phase L3",
obis_reference=obis_references.INSTANTANEOUS_ACTIVE_POWER_L3_POSITIVE,
device_class=DEVICE_CLASS_POWER,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Power Production Phase L1",
obis_reference=obis_references.INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE,
device_class=DEVICE_CLASS_POWER,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Power Production Phase L2",
obis_reference=obis_references.INSTANTANEOUS_ACTIVE_POWER_L2_NEGATIVE,
device_class=DEVICE_CLASS_POWER,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Power Production Phase L3",
obis_reference=obis_references.INSTANTANEOUS_ACTIVE_POWER_L3_NEGATIVE,
device_class=DEVICE_CLASS_POWER,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Short Power Failure Count",
obis_reference=obis_references.SHORT_POWER_FAILURE_COUNT,
entity_registry_enabled_default=False,
icon="mdi:flash-off",
),
DSMRSensor(
name="Long Power Failure Count",
obis_reference=obis_references.LONG_POWER_FAILURE_COUNT,
entity_registry_enabled_default=False,
icon="mdi:flash-off",
),
DSMRSensor(
name="Voltage Sags Phase L1",
obis_reference=obis_references.VOLTAGE_SAG_L1_COUNT,
entity_registry_enabled_default=False,
),
DSMRSensor(
name="Voltage Sags Phase L2",
obis_reference=obis_references.VOLTAGE_SAG_L2_COUNT,
entity_registry_enabled_default=False,
),
DSMRSensor(
name="Voltage Sags Phase L3",
obis_reference=obis_references.VOLTAGE_SAG_L3_COUNT,
entity_registry_enabled_default=False,
),
DSMRSensor(
name="Voltage Swells Phase L1",
obis_reference=obis_references.VOLTAGE_SWELL_L1_COUNT,
entity_registry_enabled_default=False,
icon="mdi:pulse",
),
DSMRSensor(
name="Voltage Swells Phase L2",
obis_reference=obis_references.VOLTAGE_SWELL_L2_COUNT,
entity_registry_enabled_default=False,
icon="mdi:pulse",
),
DSMRSensor(
name="Voltage Swells Phase L3",
obis_reference=obis_references.VOLTAGE_SWELL_L3_COUNT,
entity_registry_enabled_default=False,
icon="mdi:pulse",
),
DSMRSensor(
name="Voltage Phase L1",
obis_reference=obis_references.INSTANTANEOUS_VOLTAGE_L1,
device_class=DEVICE_CLASS_VOLTAGE,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Voltage Phase L2",
obis_reference=obis_references.INSTANTANEOUS_VOLTAGE_L2,
device_class=DEVICE_CLASS_VOLTAGE,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Voltage Phase L3",
obis_reference=obis_references.INSTANTANEOUS_VOLTAGE_L3,
device_class=DEVICE_CLASS_VOLTAGE,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Current Phase L1",
obis_reference=obis_references.INSTANTANEOUS_CURRENT_L1,
device_class=DEVICE_CLASS_CURRENT,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Current Phase L2",
obis_reference=obis_references.INSTANTANEOUS_CURRENT_L2,
device_class=DEVICE_CLASS_CURRENT,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Current Phase L3",
obis_reference=obis_references.INSTANTANEOUS_CURRENT_L3,
device_class=DEVICE_CLASS_CURRENT,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Energy Consumption (total)",
obis_reference=obis_references.LUXEMBOURG_ELECTRICITY_USED_TARIFF_GLOBAL,
dsmr_versions={"5L"},
force_update=True,
device_class=DEVICE_CLASS_ENERGY,
last_reset=dt.utc_from_timestamp(0),
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Energy Production (total)",
obis_reference=obis_references.LUXEMBOURG_ELECTRICITY_DELIVERED_TARIFF_GLOBAL,
dsmr_versions={"5L"},
force_update=True,
device_class=DEVICE_CLASS_ENERGY,
last_reset=dt.utc_from_timestamp(0),
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Energy Consumption (total)",
obis_reference=obis_references.ELECTRICITY_IMPORTED_TOTAL,
dsmr_versions={"2.2", "4", "5", "5B"},
force_update=True,
device_class=DEVICE_CLASS_ENERGY,
last_reset=dt.utc_from_timestamp(0),
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Gas Consumption",
obis_reference=obis_references.HOURLY_GAS_METER_READING,
dsmr_versions={"4", "5", "5L"},
force_update=True,
is_gas=True,
force_update=True,
icon="mdi:fire",
last_reset=dt.utc_from_timestamp(0),
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Gas Consumption",
obis_reference=obis_references.BELGIUM_HOURLY_GAS_METER_READING,
dsmr_versions={"5B"},
force_update=True,
is_gas=True,
force_update=True,
icon="mdi:fire",
last_reset=dt.utc_from_timestamp(0),
state_class=STATE_CLASS_MEASUREMENT,
),
DSMRSensor(
name="Gas Consumption",
obis_reference=obis_references.GAS_METER_READING,
dsmr_versions={"2.2"},
force_update=True,
is_gas=True,
force_update=True,
icon="mdi:fire",
last_reset=dt.utc_from_timestamp(0),
state_class=STATE_CLASS_MEASUREMENT,
),
]
6 changes: 6 additions & 0 deletions homeassistant/components/dsmr/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime


@dataclass
Expand All @@ -11,6 +12,11 @@ class DSMRSensor:
name: str
obis_reference: str

device_class: str | None = None
dsmr_versions: set[str] | None = None
entity_registry_enabled_default: bool = True
force_update: bool = False
icon: str | None = None
is_gas: bool = False
last_reset: datetime | None = None
state_class: str | None = None
32 changes: 10 additions & 22 deletions homeassistant/components/dsmr/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
DEVICE_NAME_ENERGY,
DEVICE_NAME_GAS,
DOMAIN,
ICON_GAS,
ICON_POWER,
ICON_POWER_FAILURE,
ICON_SWELL_SAG,
LOGGER,
SENSORS,
)
Expand Down Expand Up @@ -196,13 +192,20 @@ def __init__(self, sensor: DSMRSensor, entry: ConfigEntry) -> None:
device_serial = entry.data[CONF_SERIAL_ID_GAS]
device_name = DEVICE_NAME_GAS

self._attr_name = sensor.name
self._attr_force_update = sensor.force_update
self._attr_unique_id = f"{device_serial}_{sensor.name}".replace(" ", "_")
self._attr_device_class = sensor.device_class
self._attr_device_info = {
"identifiers": {(DOMAIN, device_serial)},
"name": device_name,
}
self._attr_entity_registry_enabled_default = (
sensor.entity_registry_enabled_default
)
self._attr_force_update = sensor.force_update
self._attr_icon = sensor.icon
self._attr_last_reset = sensor.last_reset
self._attr_name = sensor.name
self._attr_state_class = sensor.state_class
self._attr_unique_id = f"{device_serial}_{sensor.name}".replace(" ", "_")

@callback
def update_data(self, telegram: dict[str, DSMRObject]) -> None:
Expand All @@ -221,21 +224,6 @@ def get_dsmr_object_attr(self, attribute: str) -> str | None:
dsmr_object = self.telegram[self._sensor.obis_reference]
return getattr(dsmr_object, attribute, None)

@property
def icon(self) -> str | None:
"""Icon to use in the frontend, if any."""
if not self.name:
return None
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
if "Gas" in self.name:
return ICON_GAS
return None

@property
def state(self) -> StateType:
"""Return the state of sensor, if available, translate if needed."""
Expand Down
Loading
0