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
39 changes: 39 additions & 0 deletions homeassistant/components/homewizard/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from datetime import datetime, timedelta
from typing import Final

from homewizard_energy.const import Model
from homewizard_energy.models import CombinedModels, ExternalDevice

from homeassistant.components.sensor import (
Expand Down Expand Up @@ -703,6 +704,44 @@ async def async_setup_entry(
for description in SENSORS
if description.has_fn(entry.runtime_data.data)
]
# Add optional production power sensor for supported energy monitoring devices
# or plug-in battery
if entry.runtime_data.data.device.product_type in (
Model.ENERGY_SOCKET,
Model.ENERGY_METER_1_PHASE,
Model.ENERGY_METER_3_PHASE,
Model.ENERGY_METER_EASTRON_SDM230,
Model.ENERGY_METER_EASTRON_SDM630,
Model.BATTERY,
):
active_prodution_power_sensor_description = HomeWizardSensorEntityDescription(
key="active_production_power_w",
translation_key="active_production_power_w",
native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=0,
entity_registry_enabled_default=(
entry.runtime_data.data.device.product_type == Model.BATTERY
or (
(
total_export
:= entry.runtime_data.data.measurement.energy_export_kwh
)
is not None
and total_export > 0
)
),
has_fn=lambda x: True,
value_fn=lambda data: power_w * -1
if (power_w := data.measurement.power_w)
else power_w,
)
entities.append(
HomeWizardSensorEntity(
entry.runtime_data, active_prodution_power_sensor_description
)
)

# Initialize external devices
measurement = entry.runtime_data.data.measurement
Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/homewizard/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
"active_power_phase_w": {
"name": "Power phase {phase}"
},
"active_production_power_w": {
"name": "Production power"
},
"active_reactive_power_phase_var": {
"name": "Reactive power phase {phase}"
},
Expand Down
Loading
Loading