Skip to content
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
75 changes: 34 additions & 41 deletions homeassistant/components/p1_monitor/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import Literal

from homeassistant.components.sensor import (
DOMAIN as SENSOR_DOMAIN,
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
Expand Down Expand Up @@ -39,142 +38,142 @@
SENSORS_SMARTMETER: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="gas_consumption",
name="Gas Consumption",
translation_key="gas_consumption",
entity_registry_enabled_default=False,
native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
device_class=SensorDeviceClass.GAS,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SensorEntityDescription(
key="power_consumption",
name="Power Consumption",
translation_key="power_consumption",
native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="energy_consumption_high",
name="Energy Consumption - High Tariff",
translation_key="energy_consumption_high",
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SensorEntityDescription(
key="energy_consumption_low",
name="Energy Consumption - Low Tariff",
translation_key="energy_consumption_low",
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SensorEntityDescription(
key="power_production",
name="Power Production",
translation_key="power_production",
native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="energy_production_high",
name="Energy Production - High Tariff",
translation_key="energy_production_high",
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SensorEntityDescription(
key="energy_production_low",
name="Energy Production - Low Tariff",
translation_key="energy_production_low",
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SensorEntityDescription(
key="energy_tariff_period",
name="Energy Tariff Period",
translation_key="energy_tariff_period",
icon="mdi:calendar-clock",
),
)

SENSORS_PHASES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="voltage_phase_l1",
name="Voltage Phase L1",
translation_key="voltage_phase_l1",
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="voltage_phase_l2",
name="Voltage Phase L2",
translation_key="voltage_phase_l2",
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="voltage_phase_l3",
name="Voltage Phase L3",
translation_key="voltage_phase_l3",
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="current_phase_l1",
name="Current Phase L1",
translation_key="current_phase_l1",
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
device_class=SensorDeviceClass.CURRENT,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="current_phase_l2",
name="Current Phase L2",
translation_key="current_phase_l2",
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
device_class=SensorDeviceClass.CURRENT,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="current_phase_l3",
name="Current Phase L3",
translation_key="current_phase_l3",
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
device_class=SensorDeviceClass.CURRENT,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="power_consumed_phase_l1",
name="Power Consumed Phase L1",
translation_key="power_consumed_phase_l1",
native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="power_consumed_phase_l2",
name="Power Consumed Phase L2",
translation_key="power_consumed_phase_l2",
native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="power_consumed_phase_l3",
name="Power Consumed Phase L3",
translation_key="power_consumed_phase_l3",
native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="power_produced_phase_l1",
name="Power Produced Phase L1",
translation_key="power_produced_phase_l1",
native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="power_produced_phase_l2",
name="Power Produced Phase L2",
translation_key="power_produced_phase_l2",
native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="power_produced_phase_l3",
name="Power Produced Phase L3",
translation_key="power_produced_phase_l3",
native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
Expand All @@ -184,32 +183,32 @@
SENSORS_SETTINGS: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="gas_consumption_price",
name="Gas Consumption Price",
translation_key="gas_consumption_price",
entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=f"{CURRENCY_EURO}/{UnitOfVolume.CUBIC_METERS}",
),
SensorEntityDescription(
key="energy_consumption_price_low",
name="Energy Consumption Price - Low",
translation_key="energy_consumption_price_low",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=f"{CURRENCY_EURO}/{UnitOfEnergy.KILO_WATT_HOUR}",
),
SensorEntityDescription(
key="energy_consumption_price_high",
name="Energy Consumption Price - High",
translation_key="energy_consumption_price_high",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=f"{CURRENCY_EURO}/{UnitOfEnergy.KILO_WATT_HOUR}",
),
SensorEntityDescription(
key="energy_production_price_low",
name="Energy Production Price - Low",
translation_key="energy_production_price_low",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=f"{CURRENCY_EURO}/{UnitOfEnergy.KILO_WATT_HOUR}",
),
SensorEntityDescription(
key="energy_production_price_high",
name="Energy Production Price - High",
translation_key="energy_production_price_high",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=f"{CURRENCY_EURO}/{UnitOfEnergy.KILO_WATT_HOUR}",
),
Expand All @@ -218,21 +217,21 @@
SENSORS_WATERMETER: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="consumption_day",
name="Consumption Day",
translation_key="consumption_day",
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=UnitOfVolume.LITERS,
device_class=SensorDeviceClass.WATER,
),
SensorEntityDescription(
key="consumption_total",
name="Consumption Total",
translation_key="consumption_total",
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
device_class=SensorDeviceClass.WATER,
),
SensorEntityDescription(
key="pulse_count",
name="Pulse Count",
translation_key="pulse_count",
),
)

Expand All @@ -248,7 +247,6 @@ async def async_setup_entry(
coordinator=coordinator,
description=description,
name="SmartMeter",
service_key="smartmeter",
service=SERVICE_SMARTMETER,
)
for description in SENSORS_SMARTMETER
Expand All @@ -258,7 +256,6 @@ async def async_setup_entry(
coordinator=coordinator,
description=description,
name="Phases",
service_key="phases",
service=SERVICE_PHASES,
)
for description in SENSORS_PHASES
Expand All @@ -268,7 +265,6 @@ async def async_setup_entry(
coordinator=coordinator,
description=description,
name="Settings",
service_key="settings",
service=SERVICE_SETTINGS,
)
for description in SENSORS_SETTINGS
Expand All @@ -279,7 +275,6 @@ async def async_setup_entry(
coordinator=coordinator,
description=description,
name="WaterMeter",
service_key="watermeter",
service=SERVICE_WATERMETER,
)
for description in SENSORS_WATERMETER
Expand All @@ -292,30 +287,28 @@ class P1MonitorSensorEntity(
):
"""Defines an P1 Monitor sensor."""

_attr_has_entity_name = True

def __init__(
self,
*,
coordinator: P1MonitorDataUpdateCoordinator,
description: SensorEntityDescription,
service_key: Literal["smartmeter", "watermeter", "phases", "settings"],
name: str,
service: str,
service: Literal["smartmeter", "watermeter", "phases", "settings"],
) -> None:
"""Initialize P1 Monitor sensor."""
super().__init__(coordinator=coordinator)
self._service_key = service_key
self._service_key = service

self.entity_id = f"{SENSOR_DOMAIN}.{service}_{description.key}"
self.entity_description = description
self._attr_unique_id = (
f"{coordinator.config_entry.entry_id}_{service_key}_{description.key}"
f"{coordinator.config_entry.entry_id}_{service}_{description.key}"
)

self._attr_device_info = DeviceInfo(
entry_type=DeviceEntryType.SERVICE,
identifiers={
(DOMAIN, f"{coordinator.config_entry.entry_id}_{service_key}")
},
identifiers={(DOMAIN, f"{coordinator.config_entry.entry_id}_{service}")},
configuration_url=f"http://{coordinator.config_entry.data[CONF_HOST]}",
manufacturer="P1 Monitor",
name=name,
Expand Down
88 changes: 88 additions & 0 deletions homeassistant/components/p1_monitor/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,93 @@
"error": {
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
}
},
"entity": {
"sensor": {
"gas_consumption": {
"name": "Gas consumption"
},
"power_consumption": {
"name": "Power consumption"
},
"energy_consumption_high": {
"name": "Energy consumption - High tariff"
},
"energy_consumption_low": {
"name": "Energy consumption - Low tariff"
},
"power_production": {
"name": "Power production"
},
"energy_production_high": {
"name": "Energy production - High tariff"
},
"energy_production_low": {
"name": "Energy production - Low tariff"
},
"energy_tariff_period": {
"name": "Energy tariff period"
},
"voltage_phase_l1": {
"name": "Voltage phase L1"
},
"voltage_phase_l2": {
"name": "Voltage phase L2"
},
"voltage_phase_l3": {
"name": "Voltage phase L3"
},
"current_phase_l1": {
"name": "Current phase L1"
},
"current_phase_l2": {
"name": "Current phase L2"
},
"current_phase_l3": {
"name": "Current phase L3"
},
"power_consumed_phase_l1": {
"name": "Power consumed phase L1"
},
"power_consumed_phase_l2": {
"name": "Power consumed phase L2"
},
"power_consumed_phase_l3": {
"name": "Power consumed phase L3"
},
"power_produced_phase_l1": {
"name": "Power produced phase L1"
},
"power_produced_phase_l2": {
"name": "Power produced phase L2"
},
"power_produced_phase_l3": {
"name": "Power produced phase L3"
},
"gas_consumption_price": {
"name": "Gas consumption price"
},
"energy_consumption_price_low": {
"name": "Energy consumption price - Low"
},
"energy_consumption_price_high": {
"name": "Energy consumption price - High"
},
"energy_production_price_low": {
"name": "Energy production price - Low"
},
"energy_production_price_high": {
"name": "Energy production price - High"
},
"consumption_day": {
"name": "Consumption day"
},
"consumption_total": {
"name": "Consumption total"
},
"pulse_count": {
"name": "Pulse count"
}
}
}
}
Loading