Skip to content
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

Plugwise: add support for 3-phase DSMR's #85421

Merged
merged 4 commits into from
Jan 8, 2023
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
2 changes: 1 addition & 1 deletion homeassistant/components/plugwise/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"domain": "plugwise",
"name": "Plugwise",
"documentation": "https://www.home-assistant.io/integrations/plugwise",
"requirements": ["plugwise==0.25.14"],
"requirements": ["plugwise==0.27.0"],
"codeowners": ["@CoMPaTech", "@bouwew", "@brefra", "@frenck"],
"zeroconf": ["_plugwise._tcp.local."],
"config_flow": true,
Expand Down
64 changes: 64 additions & 0 deletions homeassistant/components/plugwise/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from homeassistant.const import (
LIGHT_LUX,
PERCENTAGE,
UnitOfElectricPotential,
UnitOfEnergy,
UnitOfPower,
UnitOfPressure,
Expand Down Expand Up @@ -219,6 +220,69 @@
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SensorEntityDescription(
key="electricity_phase_one_consumed",
name="Electricity phase one consumed",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="electricity_phase_two_consumed",
name="Electricity phase two consumed",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="electricity_phase_three_consumed",
name="Electricity phase three consumed",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="electricity_phase_one_produced",
name="Electricity phase one produced",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="electricity_phase_two_produced",
name="Electricity phase two produced",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="electricity_phase_three_produced",
name="Electricity phase three produced",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="voltage_phase_one",
name="Voltage phase one",
device_class=SensorDeviceClass.VOLTAGE,
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="voltage_phase_two",
name="Voltage phase two",
device_class=SensorDeviceClass.VOLTAGE,
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="voltage_phase_three",
name="Voltage phase three",
device_class=SensorDeviceClass.VOLTAGE,
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
state_class=SensorStateClass.MEASUREMENT,
),
Comment on lines +265 to +285
Copy link
Member

@frenck frenck Jan 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address this comment in a new PR.

Voltage sensors should be disabled by default, as per developer documentation:

CleanShot 2023-01-08 at 17 26 32@2x

Ref: https://developers.home-assistant.io/docs/core/entity

Voltage is really uncommon to be generally used.

/CC: @elupus

Copy link
Contributor

@elupus elupus Jan 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not battery voltage?

Ps. But I can sort of accept that it should be disabled by default since its rather not much use to know mains voltage.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frenck is right, this is line voltage of the invididual line phase leads

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.e. The P1 is used for DSMR monitoring of gas / electricity (not to confuse with the climate parts)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not battery voltage?

Ps. But I can sort of accept that it should be disabled by default since its rather not much use to know mains voltage.

Yeah, the example is a battery, but the general consensus in that example applies. Voltage is really rare to use, but it fluctuates a lot (thus causing lots of data recording, mostly unneeded).

SensorEntityDescription(
key="gas_consumed_interval",
name="Gas consumed interval",
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ plexauth==0.0.6
plexwebsocket==0.0.13

# homeassistant.components.plugwise
plugwise==0.25.14
plugwise==0.27.0

# homeassistant.components.plum_lightpad
plumlightpad==0.0.11
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ plexauth==0.0.6
plexwebsocket==0.0.13

# homeassistant.components.plugwise
plugwise==0.25.14
plugwise==0.27.0

# homeassistant.components.plum_lightpad
plumlightpad==0.0.11
Expand Down
25 changes: 25 additions & 0 deletions tests/components/plugwise/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,31 @@ def mock_smile_p1() -> Generator[None, MagicMock, None]:
yield smile


@pytest.fixture
def mock_smile_p1_2() -> Generator[None, MagicMock, None]:
"""Create a Mock P1 3-phase DSMR environment for testing exceptions."""
chosen_env = "p1v4_3ph"
with patch(
"homeassistant.components.plugwise.coordinator.Smile", autospec=True
) as smile_mock:
smile = smile_mock.return_value

smile.gateway_id = "03e65b16e4b247a29ae0d75a78cb492e"
smile.heater_id = None
smile.smile_version = "4.4.2"
smile.smile_type = "power"
smile.smile_hostname = "smile98765"
smile.smile_model = "Gateway"
smile.smile_name = "Smile P1"

smile.connect.return_value = True

smile.notifications = _read_json(chosen_env, "notifications")
smile.async_update.return_value = _read_json(chosen_env, "all_data")

yield smile


@pytest.fixture
def mock_stretch() -> Generator[None, MagicMock, None]:
"""Create a Mock Stretch environment for testing exceptions."""
Expand Down
57 changes: 57 additions & 0 deletions tests/components/plugwise/fixtures/p1v4_3ph/all_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[
{
"smile_name": "Smile P1",
"gateway_id": "03e65b16e4b247a29ae0d75a78cb492e",
"notifications": {}
},
{
"03e65b16e4b247a29ae0d75a78cb492e": {
"dev_class": "gateway",
"firmware": "4.4.2",
"hardware": "AME Smile 2.0 board",
"location": "03e65b16e4b247a29ae0d75a78cb492e",
"mac_address": "012345670001",
"model": "Gateway",
"name": "Smile P1",
"vendor": "Plugwise",
"binary_sensors": {
"plugwise_notification": false
}
},
"b82b6b3322484f2ea4e25e0bd5f3d61f": {
"dev_class": "smartmeter",
"location": "03e65b16e4b247a29ae0d75a78cb492e",
"model": "XMX5LGF0010453051839",
"name": "P1",
"vendor": "XEMEX NV",
"available": true,
"sensors": {
"net_electricity_point": 5553,
"electricity_consumed_peak_point": 0,
"electricity_consumed_off_peak_point": 5553,
"net_electricity_cumulative": 231866.539,
"electricity_consumed_peak_cumulative": 161328.641,
"electricity_consumed_off_peak_cumulative": 70537.898,
"electricity_consumed_peak_interval": 0,
"electricity_consumed_off_peak_interval": 314,
"electricity_produced_peak_point": 0,
"electricity_produced_off_peak_point": 0,
"electricity_produced_peak_cumulative": 0.0,
"electricity_produced_off_peak_cumulative": 0.0,
"electricity_produced_peak_interval": 0,
"electricity_produced_off_peak_interval": 0,
"electricity_phase_one_consumed": 1763,
"electricity_phase_two_consumed": 1703,
"electricity_phase_three_consumed": 2080,
"electricity_phase_one_produced": 0,
"electricity_phase_two_produced": 0,
"electricity_phase_three_produced": 0,
"gas_consumed_cumulative": 16811.37,
"gas_consumed_interval": 0.06,
"voltage_phase_one": 233.2,
"voltage_phase_two": 234.4,
"voltage_phase_three": 234.7
}
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
29 changes: 29 additions & 0 deletions tests/components/plugwise/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,35 @@ async def test_p1_dsmr_sensor_entities(
assert float(state.state) == 584.85


async def test_p1_3ph_dsmr_sensor_entities(
hass: HomeAssistant, mock_smile_p1_2: MagicMock, init_integration: MockConfigEntry
) -> None:
"""Test creation of power related sensor entities."""
state = hass.states.get("sensor.p1_electricity_phase_one_consumed")
assert state
assert float(state.state) == 1763.0

state = hass.states.get("sensor.p1_electricity_phase_two_consumed")
assert state
assert float(state.state) == 1703.0

state = hass.states.get("sensor.p1_electricity_phase_three_consumed")
assert state
assert float(state.state) == 2080.0

state = hass.states.get("sensor.p1_voltage_phase_one")
assert state
assert float(state.state) == 233.2

state = hass.states.get("sensor.p1_voltage_phase_two")
assert state
assert float(state.state) == 234.4

state = hass.states.get("sensor.p1_voltage_phase_three")
assert state
assert float(state.state) == 234.7


async def test_stretch_sensor_entities(
hass: HomeAssistant, mock_stretch: MagicMock, init_integration: MockConfigEntry
) -> None:
Expand Down