Skip to content

Commit

Permalink
Use entity translation in dsmr (#93017)
Browse files Browse the repository at this point in the history
* Use entity translation in dsmr

* Combine a few strings
  • Loading branch information
elupus committed May 17, 2023
1 parent 6481ee3 commit ae7930c
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 36 deletions.
69 changes: 34 additions & 35 deletions homeassistant/components/dsmr/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,33 +80,32 @@ class DSMRSensorEntityDescription(
SENSORS: tuple[DSMRSensorEntityDescription, ...] = (
DSMRSensorEntityDescription(
key="current_electricity_usage",
name="Power consumption",
translation_key="current_electricity_usage",
obis_reference=obis_references.CURRENT_ELECTRICITY_USAGE,
device_class=SensorDeviceClass.POWER,
force_update=True,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key="current_electricity_delivery",
name="Power production",
translation_key="current_electricity_delivery",
obis_reference=obis_references.CURRENT_ELECTRICITY_DELIVERY,
device_class=SensorDeviceClass.POWER,
force_update=True,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key="electricity_active_tariff",
name="Active tariff",
translation_key="electricity_active_tariff",
obis_reference=obis_references.ELECTRICITY_ACTIVE_TARIFF,
dsmr_versions={"2.2", "4", "5", "5B", "5L"},
device_class=SensorDeviceClass.ENUM,
options=["low", "normal"],
translation_key="electricity_tariff",
icon="mdi:flash",
),
DSMRSensorEntityDescription(
key="electricity_used_tariff_1",
name="Energy consumption (tarif 1)",
translation_key="electricity_used_tariff_1",
obis_reference=obis_references.ELECTRICITY_USED_TARIFF_1,
dsmr_versions={"2.2", "4", "5", "5B", "5L"},
device_class=SensorDeviceClass.ENERGY,
Expand All @@ -115,7 +114,7 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="electricity_used_tariff_2",
name="Energy consumption (tarif 2)",
translation_key="electricity_used_tariff_2",
obis_reference=obis_references.ELECTRICITY_USED_TARIFF_2,
dsmr_versions={"2.2", "4", "5", "5B", "5L"},
force_update=True,
Expand All @@ -124,7 +123,7 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="electricity_delivered_tariff_1",
name="Energy production (tarif 1)",
translation_key="electricity_delivered_tariff_1",
obis_reference=obis_references.ELECTRICITY_DELIVERED_TARIFF_1,
dsmr_versions={"2.2", "4", "5", "5B", "5L"},
force_update=True,
Expand All @@ -133,7 +132,7 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="electricity_delivered_tariff_2",
name="Energy production (tarif 2)",
translation_key="electricity_delivered_tariff_2",
obis_reference=obis_references.ELECTRICITY_DELIVERED_TARIFF_2,
dsmr_versions={"2.2", "4", "5", "5B", "5L"},
force_update=True,
Expand All @@ -142,55 +141,55 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="instantaneous_active_power_l1_positive",
name="Power consumption phase L1",
translation_key="instantaneous_active_power_l1_positive",
obis_reference=obis_references.INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE,
device_class=SensorDeviceClass.POWER,
entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key="instantaneous_active_power_l2_positive",
name="Power consumption phase L2",
translation_key="instantaneous_active_power_l2_positive",
obis_reference=obis_references.INSTANTANEOUS_ACTIVE_POWER_L2_POSITIVE,
device_class=SensorDeviceClass.POWER,
entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key="instantaneous_active_power_l3_positive",
name="Power consumption phase L3",
translation_key="instantaneous_active_power_l3_positive",
obis_reference=obis_references.INSTANTANEOUS_ACTIVE_POWER_L3_POSITIVE,
device_class=SensorDeviceClass.POWER,
entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key="instantaneous_active_power_l1_negative",
name="Power production phase L1",
translation_key="instantaneous_active_power_l1_negative",
obis_reference=obis_references.INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE,
device_class=SensorDeviceClass.POWER,
entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key="instantaneous_active_power_l2_negative",
name="Power production phase L2",
translation_key="instantaneous_active_power_l2_negative",
obis_reference=obis_references.INSTANTANEOUS_ACTIVE_POWER_L2_NEGATIVE,
device_class=SensorDeviceClass.POWER,
entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key="instantaneous_active_power_l3_negative",
name="Power production phase L3",
translation_key="instantaneous_active_power_l3_negative",
obis_reference=obis_references.INSTANTANEOUS_ACTIVE_POWER_L3_NEGATIVE,
device_class=SensorDeviceClass.POWER,
entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT,
),
DSMRSensorEntityDescription(
key="short_power_failure_count",
name="Short power failure count",
translation_key="short_power_failure_count",
obis_reference=obis_references.SHORT_POWER_FAILURE_COUNT,
dsmr_versions={"2.2", "4", "5", "5B", "5L"},
entity_registry_enabled_default=False,
Expand All @@ -199,7 +198,7 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="long_power_failure_count",
name="Long power failure count",
translation_key="long_power_failure_count",
obis_reference=obis_references.LONG_POWER_FAILURE_COUNT,
dsmr_versions={"2.2", "4", "5", "5B", "5L"},
entity_registry_enabled_default=False,
Expand All @@ -208,31 +207,31 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="voltage_sag_l1_count",
name="Voltage sags phase L1",
translation_key="voltage_sag_l1_count",
obis_reference=obis_references.VOLTAGE_SAG_L1_COUNT,
dsmr_versions={"2.2", "4", "5", "5B", "5L"},
entity_registry_enabled_default=False,
entity_category=EntityCategory.DIAGNOSTIC,
),
DSMRSensorEntityDescription(
key="voltage_sag_l2_count",
name="Voltage sags phase L2",
translation_key="voltage_sag_l2_count",
obis_reference=obis_references.VOLTAGE_SAG_L2_COUNT,
dsmr_versions={"2.2", "4", "5", "5B", "5L"},
entity_registry_enabled_default=False,
entity_category=EntityCategory.DIAGNOSTIC,
),
DSMRSensorEntityDescription(
key="voltage_sag_l3_count",
name="Voltage sags phase L3",
translation_key="voltage_sag_l3_count",
obis_reference=obis_references.VOLTAGE_SAG_L3_COUNT,
dsmr_versions={"2.2", "4", "5", "5B", "5L"},
entity_registry_enabled_default=False,
entity_category=EntityCategory.DIAGNOSTIC,
),
DSMRSensorEntityDescription(
key="voltage_swell_l1_count",
name="Voltage swells phase L1",
translation_key="voltage_swell_l1_count",
obis_reference=obis_references.VOLTAGE_SWELL_L1_COUNT,
dsmr_versions={"2.2", "4", "5", "5B", "5L"},
entity_registry_enabled_default=False,
Expand All @@ -241,7 +240,7 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="voltage_swell_l2_count",
name="Voltage swells phase L2",
translation_key="voltage_swell_l2_count",
obis_reference=obis_references.VOLTAGE_SWELL_L2_COUNT,
dsmr_versions={"2.2", "4", "5", "5B", "5L"},
entity_registry_enabled_default=False,
Expand All @@ -250,7 +249,7 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="voltage_swell_l3_count",
name="Voltage swells phase L3",
translation_key="voltage_swell_l3_count",
obis_reference=obis_references.VOLTAGE_SWELL_L3_COUNT,
dsmr_versions={"2.2", "4", "5", "5B", "5L"},
entity_registry_enabled_default=False,
Expand All @@ -259,7 +258,7 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="instantaneous_voltage_l1",
name="Voltage phase L1",
translation_key="instantaneous_voltage_l1",
obis_reference=obis_references.INSTANTANEOUS_VOLTAGE_L1,
device_class=SensorDeviceClass.VOLTAGE,
entity_registry_enabled_default=False,
Expand All @@ -268,7 +267,7 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="instantaneous_voltage_l2",
name="Voltage phase L2",
translation_key="instantaneous_voltage_l2",
obis_reference=obis_references.INSTANTANEOUS_VOLTAGE_L2,
device_class=SensorDeviceClass.VOLTAGE,
entity_registry_enabled_default=False,
Expand All @@ -277,7 +276,7 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="instantaneous_voltage_l3",
name="Voltage phase L3",
translation_key="instantaneous_voltage_l3",
obis_reference=obis_references.INSTANTANEOUS_VOLTAGE_L3,
device_class=SensorDeviceClass.VOLTAGE,
entity_registry_enabled_default=False,
Expand All @@ -286,7 +285,7 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="instantaneous_current_l1",
name="Current phase L1",
translation_key="instantaneous_current_l1",
obis_reference=obis_references.INSTANTANEOUS_CURRENT_L1,
device_class=SensorDeviceClass.CURRENT,
entity_registry_enabled_default=False,
Expand All @@ -295,7 +294,7 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="instantaneous_current_l2",
name="Current phase L2",
translation_key="instantaneous_current_l2",
obis_reference=obis_references.INSTANTANEOUS_CURRENT_L2,
device_class=SensorDeviceClass.CURRENT,
entity_registry_enabled_default=False,
Expand All @@ -304,7 +303,7 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="instantaneous_current_l3",
name="Current phase L3",
translation_key="instantaneous_current_l3",
obis_reference=obis_references.INSTANTANEOUS_CURRENT_L3,
device_class=SensorDeviceClass.CURRENT,
entity_registry_enabled_default=False,
Expand All @@ -313,7 +312,7 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="belgium_max_power_per_phase",
name="Max power per phase",
translation_key="max_power_per_phase",
obis_reference=obis_references.BELGIUM_MAX_POWER_PER_PHASE,
dsmr_versions={"5B"},
device_class=SensorDeviceClass.POWER,
Expand All @@ -323,7 +322,7 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="belgium_max_current_per_phase",
name="Max current per phase",
translation_key="max_current_per_phase",
obis_reference=obis_references.BELGIUM_MAX_CURRENT_PER_PHASE,
dsmr_versions={"5B"},
device_class=SensorDeviceClass.POWER,
Expand All @@ -333,7 +332,7 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="electricity_imported_total",
name="Energy consumption (total)",
translation_key="electricity_imported_total",
obis_reference=obis_references.ELECTRICITY_IMPORTED_TOTAL,
dsmr_versions={"5L", "5S", "Q3D"},
force_update=True,
Expand All @@ -342,7 +341,7 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="electricity_exported_total",
name="Energy production (total)",
translation_key="electricity_exported_total",
obis_reference=obis_references.ELECTRICITY_EXPORTED_TOTAL,
dsmr_versions={"5L", "5S", "Q3D"},
force_update=True,
Expand All @@ -351,7 +350,7 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="hourly_gas_meter_reading",
name="Gas consumption",
translation_key="gas_meter_reading",
obis_reference=obis_references.HOURLY_GAS_METER_READING,
dsmr_versions={"4", "5", "5L"},
is_gas=True,
Expand All @@ -361,7 +360,7 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="belgium_5min_gas_meter_reading",
name="Gas consumption",
translation_key="gas_meter_reading",
obis_reference=obis_references.BELGIUM_5MIN_GAS_METER_READING,
dsmr_versions={"5B"},
is_gas=True,
Expand All @@ -371,7 +370,7 @@ class DSMRSensorEntityDescription(
),
DSMRSensorEntityDescription(
key="gas_meter_reading",
name="Gas consumption",
translation_key="gas_meter_reading",
obis_reference=obis_references.GAS_METER_READING,
dsmr_versions={"2.2"},
is_gas=True,
Expand Down

0 comments on commit ae7930c

Please sign in to comment.