1 """Support for Enphase Envoy solar energy monitor."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass, replace
9 from operator
import attrgetter
10 from typing
import TYPE_CHECKING
12 from pyenphase
import (
14 EnvoyEnchargeAggregate,
18 EnvoySystemConsumption,
19 EnvoySystemProduction,
21 from pyenphase.const
import PHASENAMES
22 from pyenphase.models.meters
import (
33 SensorEntityDescription,
39 UnitOfElectricCurrent,
40 UnitOfElectricPotential,
52 from .const
import DOMAIN
53 from .coordinator
import EnphaseConfigEntry, EnphaseUpdateCoordinator
54 from .entity
import EnvoyBaseEntity
57 _LOGGER = logging.getLogger(__name__)
59 INVERTERS_KEY =
"inverters"
60 LAST_REPORTED_KEY =
"last_reported"
63 @dataclass(frozen=True, kw_only=True)
65 """Describes an Envoy inverter sensor entity."""
67 value_fn: Callable[[EnvoyInverter], datetime.datetime | float]
74 native_unit_of_measurement=UnitOfPower.WATT,
75 state_class=SensorStateClass.MEASUREMENT,
76 device_class=SensorDeviceClass.POWER,
77 value_fn=attrgetter(
"last_report_watts"),
80 key=LAST_REPORTED_KEY,
81 translation_key=LAST_REPORTED_KEY,
82 device_class=SensorDeviceClass.TIMESTAMP,
83 entity_registry_enabled_default=
False,
84 value_fn=
lambda inverter: dt_util.utc_from_timestamp(inverter.last_report_date),
89 @dataclass(frozen=True, kw_only=True)
91 """Describes an Envoy production sensor entity."""
93 value_fn: Callable[[EnvoySystemProduction], int]
97 PRODUCTION_SENSORS = (
100 translation_key=
"current_power_production",
101 native_unit_of_measurement=UnitOfPower.WATT,
102 state_class=SensorStateClass.MEASUREMENT,
103 device_class=SensorDeviceClass.POWER,
104 suggested_unit_of_measurement=UnitOfPower.KILO_WATT,
105 suggested_display_precision=3,
106 value_fn=attrgetter(
"watts_now"),
110 key=
"daily_production",
111 translation_key=
"daily_production",
112 native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
113 state_class=SensorStateClass.TOTAL_INCREASING,
114 device_class=SensorDeviceClass.ENERGY,
115 suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
116 suggested_display_precision=2,
117 value_fn=attrgetter(
"watt_hours_today"),
121 key=
"seven_days_production",
122 translation_key=
"seven_days_production",
123 native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
124 device_class=SensorDeviceClass.ENERGY,
125 suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
126 suggested_display_precision=1,
127 value_fn=attrgetter(
"watt_hours_last_7_days"),
131 key=
"lifetime_production",
132 translation_key=
"lifetime_production",
133 native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
134 state_class=SensorStateClass.TOTAL_INCREASING,
135 device_class=SensorDeviceClass.ENERGY,
136 suggested_unit_of_measurement=UnitOfEnergy.MEGA_WATT_HOUR,
137 suggested_display_precision=3,
138 value_fn=attrgetter(
"watt_hours_lifetime"),
144 PRODUCTION_PHASE_SENSORS = {
145 (on_phase := PHASENAMES[phase]): [
148 key=f
"{sensor.key}_l{phase + 1}",
149 translation_key=f
"{sensor.translation_key}_phase",
150 entity_registry_enabled_default=
False,
152 translation_placeholders={
"phase_name": f
"l{phase + 1}"},
154 for sensor
in list(PRODUCTION_SENSORS)
156 for phase
in range(3)
160 @dataclass(frozen=True, kw_only=True)
162 """Describes an Envoy consumption sensor entity."""
164 value_fn: Callable[[EnvoySystemConsumption], int]
168 CONSUMPTION_SENSORS = (
171 translation_key=
"current_power_consumption",
172 native_unit_of_measurement=UnitOfPower.WATT,
173 state_class=SensorStateClass.MEASUREMENT,
174 device_class=SensorDeviceClass.POWER,
175 suggested_unit_of_measurement=UnitOfPower.KILO_WATT,
176 suggested_display_precision=3,
177 value_fn=attrgetter(
"watts_now"),
181 key=
"daily_consumption",
182 translation_key=
"daily_consumption",
183 native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
184 state_class=SensorStateClass.TOTAL_INCREASING,
185 device_class=SensorDeviceClass.ENERGY,
186 suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
187 suggested_display_precision=2,
188 value_fn=attrgetter(
"watt_hours_today"),
192 key=
"seven_days_consumption",
193 translation_key=
"seven_days_consumption",
194 native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
195 device_class=SensorDeviceClass.ENERGY,
196 suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
197 suggested_display_precision=1,
198 value_fn=attrgetter(
"watt_hours_last_7_days"),
202 key=
"lifetime_consumption",
203 translation_key=
"lifetime_consumption",
204 native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
205 state_class=SensorStateClass.TOTAL_INCREASING,
206 device_class=SensorDeviceClass.ENERGY,
207 suggested_unit_of_measurement=UnitOfEnergy.MEGA_WATT_HOUR,
208 suggested_display_precision=3,
209 value_fn=attrgetter(
"watt_hours_lifetime"),
215 CONSUMPTION_PHASE_SENSORS = {
216 (on_phase := PHASENAMES[phase]): [
219 key=f
"{sensor.key}_l{phase + 1}",
220 translation_key=f
"{sensor.translation_key}_phase",
221 entity_registry_enabled_default=
False,
223 translation_placeholders={
"phase_name": f
"l{phase + 1}"},
225 for sensor
in list(CONSUMPTION_SENSORS)
227 for phase
in range(3)
231 NET_CONSUMPTION_SENSORS = (
233 key=
"balanced_net_consumption",
234 translation_key=
"balanced_net_consumption",
235 entity_registry_enabled_default=
False,
236 native_unit_of_measurement=UnitOfPower.WATT,
237 state_class=SensorStateClass.MEASUREMENT,
238 device_class=SensorDeviceClass.POWER,
239 suggested_unit_of_measurement=UnitOfPower.KILO_WATT,
240 suggested_display_precision=3,
241 value_fn=attrgetter(
"watts_now"),
245 key=
"lifetime_balanced_net_consumption",
246 translation_key=
"lifetime_balanced_net_consumption",
247 entity_registry_enabled_default=
False,
248 native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
249 state_class=SensorStateClass.TOTAL,
250 device_class=SensorDeviceClass.ENERGY,
251 suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
252 suggested_display_precision=3,
253 value_fn=attrgetter(
"watt_hours_lifetime"),
259 NET_CONSUMPTION_PHASE_SENSORS = {
260 (on_phase := PHASENAMES[phase]): [
263 key=f
"{sensor.key}_l{phase + 1}",
264 translation_key=f
"{sensor.translation_key}_phase",
265 entity_registry_enabled_default=
False,
267 translation_placeholders={
"phase_name": f
"l{phase + 1}"},
269 for sensor
in list(NET_CONSUMPTION_SENSORS)
271 for phase
in range(3)
275 @dataclass(frozen=True, kw_only=True)
277 """Describes an Envoy CT sensor entity."""
281 int | float | str | CtType | CtMeterStatus | CtStatusFlags | CtState |
None,
286 CT_NET_CONSUMPTION_SENSORS = (
288 key=
"lifetime_net_consumption",
289 translation_key=
"lifetime_net_consumption",
290 native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
291 state_class=SensorStateClass.TOTAL_INCREASING,
292 device_class=SensorDeviceClass.ENERGY,
293 suggested_unit_of_measurement=UnitOfEnergy.MEGA_WATT_HOUR,
294 suggested_display_precision=3,
295 value_fn=attrgetter(
"energy_delivered"),
299 key=
"lifetime_net_production",
300 translation_key=
"lifetime_net_production",
301 native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
302 state_class=SensorStateClass.TOTAL_INCREASING,
303 device_class=SensorDeviceClass.ENERGY,
304 suggested_unit_of_measurement=UnitOfEnergy.MEGA_WATT_HOUR,
305 suggested_display_precision=3,
306 value_fn=attrgetter(
"energy_received"),
310 key=
"net_consumption",
311 translation_key=
"net_consumption",
312 native_unit_of_measurement=UnitOfPower.WATT,
313 state_class=SensorStateClass.MEASUREMENT,
314 device_class=SensorDeviceClass.POWER,
315 suggested_unit_of_measurement=UnitOfPower.KILO_WATT,
316 suggested_display_precision=3,
317 value_fn=attrgetter(
"active_power"),
322 translation_key=
"net_ct_frequency",
323 native_unit_of_measurement=UnitOfFrequency.HERTZ,
324 state_class=SensorStateClass.MEASUREMENT,
325 device_class=SensorDeviceClass.FREQUENCY,
326 suggested_display_precision=1,
327 entity_registry_enabled_default=
False,
328 value_fn=attrgetter(
"frequency"),
333 translation_key=
"net_ct_voltage",
334 native_unit_of_measurement=UnitOfElectricPotential.VOLT,
335 state_class=SensorStateClass.MEASUREMENT,
336 device_class=SensorDeviceClass.VOLTAGE,
337 suggested_unit_of_measurement=UnitOfElectricPotential.VOLT,
338 suggested_display_precision=1,
339 entity_registry_enabled_default=
False,
340 value_fn=attrgetter(
"voltage"),
344 key=
"net_ct_current",
345 translation_key=
"net_ct_current",
346 native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
347 state_class=SensorStateClass.MEASUREMENT,
348 device_class=SensorDeviceClass.CURRENT,
349 suggested_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
350 suggested_display_precision=3,
351 entity_registry_enabled_default=
False,
352 value_fn=attrgetter(
"current"),
356 key=
"net_ct_powerfactor",
357 translation_key=
"net_ct_powerfactor",
358 device_class=SensorDeviceClass.POWER_FACTOR,
359 state_class=SensorStateClass.MEASUREMENT,
360 suggested_display_precision=2,
361 entity_registry_enabled_default=
False,
362 value_fn=attrgetter(
"power_factor"),
366 key=
"net_consumption_ct_metering_status",
367 translation_key=
"net_ct_metering_status",
368 device_class=SensorDeviceClass.ENUM,
369 options=
list(CtMeterStatus),
370 entity_registry_enabled_default=
False,
371 value_fn=attrgetter(
"metering_status"),
375 key=
"net_consumption_ct_status_flags",
376 translation_key=
"net_ct_status_flags",
378 entity_registry_enabled_default=
False,
379 value_fn=
lambda ct: 0
if ct.status_flags
is None else len(ct.status_flags),
385 CT_NET_CONSUMPTION_PHASE_SENSORS = {
386 (on_phase := PHASENAMES[phase]): [
389 key=f
"{sensor.key}_l{phase + 1}",
390 translation_key=f
"{sensor.translation_key}_phase",
391 entity_registry_enabled_default=
False,
393 translation_placeholders={
"phase_name": f
"l{phase + 1}"},
395 for sensor
in list(CT_NET_CONSUMPTION_SENSORS)
397 for phase
in range(3)
400 CT_PRODUCTION_SENSORS = (
402 key=
"production_ct_frequency",
403 translation_key=
"production_ct_frequency",
404 native_unit_of_measurement=UnitOfFrequency.HERTZ,
405 state_class=SensorStateClass.MEASUREMENT,
406 device_class=SensorDeviceClass.FREQUENCY,
407 suggested_display_precision=1,
408 entity_registry_enabled_default=
False,
409 value_fn=attrgetter(
"frequency"),
413 key=
"production_ct_voltage",
414 translation_key=
"production_ct_voltage",
415 native_unit_of_measurement=UnitOfElectricPotential.VOLT,
416 state_class=SensorStateClass.MEASUREMENT,
417 device_class=SensorDeviceClass.VOLTAGE,
418 suggested_unit_of_measurement=UnitOfElectricPotential.VOLT,
419 suggested_display_precision=1,
420 entity_registry_enabled_default=
False,
421 value_fn=attrgetter(
"voltage"),
425 key=
"production_ct_current",
426 translation_key=
"production_ct_current",
427 native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
428 state_class=SensorStateClass.MEASUREMENT,
429 device_class=SensorDeviceClass.CURRENT,
430 suggested_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
431 suggested_display_precision=3,
432 entity_registry_enabled_default=
False,
433 value_fn=attrgetter(
"current"),
437 key=
"production_ct_powerfactor",
438 translation_key=
"production_ct_powerfactor",
439 device_class=SensorDeviceClass.POWER_FACTOR,
440 state_class=SensorStateClass.MEASUREMENT,
441 suggested_display_precision=2,
442 entity_registry_enabled_default=
False,
443 value_fn=attrgetter(
"power_factor"),
447 key=
"production_ct_metering_status",
448 translation_key=
"production_ct_metering_status",
449 device_class=SensorDeviceClass.ENUM,
450 options=
list(CtMeterStatus),
451 entity_registry_enabled_default=
False,
452 value_fn=attrgetter(
"metering_status"),
456 key=
"production_ct_status_flags",
457 translation_key=
"production_ct_status_flags",
459 entity_registry_enabled_default=
False,
460 value_fn=
lambda ct: 0
if ct.status_flags
is None else len(ct.status_flags),
465 CT_PRODUCTION_PHASE_SENSORS = {
466 (on_phase := PHASENAMES[phase]): [
469 key=f
"{sensor.key}_l{phase + 1}",
470 translation_key=f
"{sensor.translation_key}_phase",
471 entity_registry_enabled_default=
False,
473 translation_placeholders={
"phase_name": f
"l{phase + 1}"},
475 for sensor
in list(CT_PRODUCTION_SENSORS)
477 for phase
in range(3)
480 CT_STORAGE_SENSORS = (
482 key=
"lifetime_battery_discharged",
483 translation_key=
"lifetime_battery_discharged",
484 native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
485 state_class=SensorStateClass.TOTAL_INCREASING,
486 device_class=SensorDeviceClass.ENERGY,
487 suggested_unit_of_measurement=UnitOfEnergy.MEGA_WATT_HOUR,
488 suggested_display_precision=3,
489 value_fn=attrgetter(
"energy_delivered"),
493 key=
"lifetime_battery_charged",
494 translation_key=
"lifetime_battery_charged",
495 native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
496 state_class=SensorStateClass.TOTAL_INCREASING,
497 device_class=SensorDeviceClass.ENERGY,
498 suggested_unit_of_measurement=UnitOfEnergy.MEGA_WATT_HOUR,
499 suggested_display_precision=3,
500 value_fn=attrgetter(
"energy_received"),
504 key=
"battery_discharge",
505 translation_key=
"battery_discharge",
506 native_unit_of_measurement=UnitOfPower.WATT,
507 state_class=SensorStateClass.MEASUREMENT,
508 device_class=SensorDeviceClass.POWER,
509 suggested_unit_of_measurement=UnitOfPower.KILO_WATT,
510 suggested_display_precision=3,
511 value_fn=attrgetter(
"active_power"),
515 key=
"storage_ct_frequency",
516 translation_key=
"storage_ct_frequency",
517 native_unit_of_measurement=UnitOfFrequency.HERTZ,
518 state_class=SensorStateClass.MEASUREMENT,
519 device_class=SensorDeviceClass.FREQUENCY,
520 suggested_display_precision=1,
521 entity_registry_enabled_default=
False,
522 value_fn=attrgetter(
"frequency"),
526 key=
"storage_voltage",
527 translation_key=
"storage_ct_voltage",
528 native_unit_of_measurement=UnitOfElectricPotential.VOLT,
529 state_class=SensorStateClass.MEASUREMENT,
530 device_class=SensorDeviceClass.VOLTAGE,
531 suggested_unit_of_measurement=UnitOfElectricPotential.VOLT,
532 suggested_display_precision=1,
533 entity_registry_enabled_default=
False,
534 value_fn=attrgetter(
"voltage"),
538 key=
"storage_ct_current",
539 translation_key=
"storage_ct_current",
540 native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
541 state_class=SensorStateClass.MEASUREMENT,
542 device_class=SensorDeviceClass.CURRENT,
543 suggested_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
544 suggested_display_precision=3,
545 entity_registry_enabled_default=
False,
546 value_fn=attrgetter(
"current"),
550 key=
"storage_ct_powerfactor",
551 translation_key=
"storage_ct_powerfactor",
552 device_class=SensorDeviceClass.POWER_FACTOR,
553 state_class=SensorStateClass.MEASUREMENT,
554 suggested_display_precision=2,
555 entity_registry_enabled_default=
False,
556 value_fn=attrgetter(
"power_factor"),
560 key=
"storage_ct_metering_status",
561 translation_key=
"storage_ct_metering_status",
562 device_class=SensorDeviceClass.ENUM,
563 options=
list(CtMeterStatus),
564 entity_registry_enabled_default=
False,
565 value_fn=attrgetter(
"metering_status"),
569 key=
"storage_ct_status_flags",
570 translation_key=
"storage_ct_status_flags",
572 entity_registry_enabled_default=
False,
573 value_fn=
lambda ct: 0
if ct.status_flags
is None else len(ct.status_flags),
579 CT_STORAGE_PHASE_SENSORS = {
580 (on_phase := PHASENAMES[phase]): [
583 key=f
"{sensor.key}_l{phase + 1}",
584 translation_key=f
"{sensor.translation_key}_phase",
585 entity_registry_enabled_default=
False,
587 translation_placeholders={
"phase_name": f
"l{phase + 1}"},
589 for sensor
in list(CT_STORAGE_SENSORS)
591 for phase
in range(3)
595 @dataclass(frozen=True, kw_only=True)
597 """Describes an Envoy Encharge sensor entity."""
599 value_fn: Callable[[EnvoyEncharge], datetime.datetime | int | float]
602 @dataclass(frozen=True)
604 """Mixin for required keys."""
607 @dataclass(frozen=
True, kw_only=
True)
609 """Describes an Envoy Encharge sensor entity."""
611 value_fn: Callable[[EnvoyEnchargePower], int | float]
614 ENCHARGE_INVENTORY_SENSORS = (
617 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
618 device_class=SensorDeviceClass.TEMPERATURE,
619 value_fn=attrgetter(
"temperature"),
622 key=LAST_REPORTED_KEY,
623 translation_key=LAST_REPORTED_KEY,
624 native_unit_of_measurement=
None,
625 device_class=SensorDeviceClass.TIMESTAMP,
626 value_fn=
lambda encharge: dt_util.utc_from_timestamp(encharge.last_report_date),
629 ENCHARGE_POWER_SENSORS = (
632 native_unit_of_measurement=PERCENTAGE,
633 device_class=SensorDeviceClass.BATTERY,
634 value_fn=attrgetter(
"soc"),
637 key=
"apparent_power_mva",
638 native_unit_of_measurement=UnitOfApparentPower.VOLT_AMPERE,
639 device_class=SensorDeviceClass.APPARENT_POWER,
640 value_fn=
lambda encharge: encharge.apparent_power_mva * 0.001,
644 native_unit_of_measurement=UnitOfPower.WATT,
645 device_class=SensorDeviceClass.POWER,
646 value_fn=
lambda encharge: encharge.real_power_mw * 0.001,
651 @dataclass(frozen=True, kw_only=True)
653 """Describes an Envoy Encharge sensor entity."""
655 value_fn: Callable[[EnvoyEnpower], datetime.datetime | int | float]
661 native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
662 device_class=SensorDeviceClass.TEMPERATURE,
663 value_fn=attrgetter(
"temperature"),
666 key=LAST_REPORTED_KEY,
667 translation_key=LAST_REPORTED_KEY,
668 device_class=SensorDeviceClass.TIMESTAMP,
669 value_fn=
lambda enpower: dt_util.utc_from_timestamp(enpower.last_report_date),
674 @dataclass(frozen=True)
676 """Mixin for required keys."""
679 @dataclass(frozen=
True, kw_only=
True)
681 """Describes an Envoy Encharge sensor entity."""
683 value_fn: Callable[[EnvoyEnchargeAggregate], int]
686 ENCHARGE_AGGREGATE_SENSORS = (
689 native_unit_of_measurement=PERCENTAGE,
690 device_class=SensorDeviceClass.BATTERY,
691 value_fn=attrgetter(
"state_of_charge"),
695 translation_key=
"reserve_soc",
696 native_unit_of_measurement=PERCENTAGE,
697 device_class=SensorDeviceClass.BATTERY,
698 value_fn=attrgetter(
"reserve_state_of_charge"),
701 key=
"available_energy",
702 translation_key=
"available_energy",
703 native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
704 device_class=SensorDeviceClass.ENERGY,
705 value_fn=attrgetter(
"available_energy"),
708 key=
"reserve_energy",
709 translation_key=
"reserve_energy",
710 native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
711 device_class=SensorDeviceClass.ENERGY,
712 value_fn=attrgetter(
"backup_reserve"),
716 translation_key=
"max_capacity",
717 native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
718 device_class=SensorDeviceClass.ENERGY,
719 value_fn=attrgetter(
"max_available_capacity"),
726 config_entry: EnphaseConfigEntry,
727 async_add_entities: AddEntitiesCallback,
729 """Set up envoy sensor platform."""
730 coordinator = config_entry.runtime_data
731 envoy_data = coordinator.envoy.data
732 assert envoy_data
is not None
733 _LOGGER.debug(
"Envoy data: %s", envoy_data)
735 entities: list[Entity] = [
737 for description
in PRODUCTION_SENSORS
739 if envoy_data.system_consumption:
742 for description
in CONSUMPTION_SENSORS
744 if envoy_data.system_net_consumption:
747 for description
in NET_CONSUMPTION_SENSORS
750 if envoy_data.system_production_phases:
753 for use_phase, phase
in envoy_data.system_production_phases.items()
754 for description
in PRODUCTION_PHASE_SENSORS[use_phase]
758 if envoy_data.system_consumption_phases:
761 for use_phase, phase
in envoy_data.system_consumption_phases.items()
762 for description
in CONSUMPTION_PHASE_SENSORS[use_phase]
766 if envoy_data.system_net_consumption_phases:
769 for use_phase, phase
in envoy_data.system_net_consumption_phases.items()
770 for description
in NET_CONSUMPTION_PHASE_SENSORS[use_phase]
774 if ctmeter := envoy_data.ctmeter_consumption:
777 for description
in CT_NET_CONSUMPTION_SENSORS
778 if ctmeter.measurement_type == CtType.NET_CONSUMPTION
781 if phase_data := envoy_data.ctmeter_consumption_phases:
784 for use_phase, phase
in phase_data.items()
785 for description
in CT_NET_CONSUMPTION_PHASE_SENSORS[use_phase]
786 if phase.measurement_type == CtType.NET_CONSUMPTION
789 if ctmeter := envoy_data.ctmeter_production:
792 for description
in CT_PRODUCTION_SENSORS
793 if ctmeter.measurement_type == CtType.PRODUCTION
796 if phase_data := envoy_data.ctmeter_production_phases:
799 for use_phase, phase
in phase_data.items()
800 for description
in CT_PRODUCTION_PHASE_SENSORS[use_phase]
801 if phase.measurement_type == CtType.PRODUCTION
804 if ctmeter := envoy_data.ctmeter_storage:
807 for description
in CT_STORAGE_SENSORS
808 if ctmeter.measurement_type == CtType.STORAGE
811 if phase_data := envoy_data.ctmeter_storage_phases:
814 for use_phase, phase
in phase_data.items()
815 for description
in CT_STORAGE_PHASE_SENSORS[use_phase]
816 if phase.measurement_type == CtType.STORAGE
819 if envoy_data.inverters:
822 for description
in INVERTER_SENSORS
823 for inverter
in envoy_data.inverters
826 if envoy_data.encharge_inventory:
829 for description
in ENCHARGE_INVENTORY_SENSORS
830 for encharge
in envoy_data.encharge_inventory
832 if envoy_data.encharge_power:
835 for description
in ENCHARGE_POWER_SENSORS
836 for encharge
in envoy_data.encharge_power
838 if envoy_data.encharge_aggregate:
841 for description
in ENCHARGE_AGGREGATE_SENSORS
843 if envoy_data.enpower:
846 for description
in ENPOWER_SENSORS
853 """Defines a base envoy entity."""
856 class EnvoySystemSensorEntity(EnvoySensorBaseEntity):
857 """Envoy system base entity."""
863 coordinator: EnphaseUpdateCoordinator,
864 description: SensorEntityDescription,
866 """Initialize Envoy entity."""
867 super().
__init__(coordinator, description)
871 manufacturer=
"Enphase",
872 model=coordinator.envoy.envoy_model,
873 name=coordinator.name,
874 sw_version=
str(coordinator.envoy.firmware),
875 hw_version=coordinator.envoy.part_number,
881 """Envoy production entity."""
883 entity_description: EnvoyProductionSensorEntityDescription
887 """Return the state of the sensor."""
888 system_production = self.
datadatadata.system_production
889 assert system_production
is not None
894 """Envoy consumption entity."""
896 entity_description: EnvoyConsumptionSensorEntityDescription
900 """Return the state of the sensor."""
901 system_consumption = self.
datadatadata.system_consumption
902 assert system_consumption
is not None
907 """Envoy consumption entity."""
909 entity_description: EnvoyConsumptionSensorEntityDescription
913 """Return the state of the sensor."""
914 system_net_consumption = self.
datadatadata.system_net_consumption
915 assert system_net_consumption
is not None
920 """Envoy phase production entity."""
922 entity_description: EnvoyProductionSensorEntityDescription
926 """Return the state of the sensor."""
929 assert self.
datadatadata.system_production_phases
932 system_production := self.
datadatadata.system_production_phases[
941 """Envoy phase consumption entity."""
943 entity_description: EnvoyConsumptionSensorEntityDescription
947 """Return the state of the sensor."""
950 assert self.
datadatadata.system_consumption_phases
953 system_consumption := self.
datadatadata.system_consumption_phases[
962 """Envoy phase consumption entity."""
964 entity_description: EnvoyConsumptionSensorEntityDescription
968 """Return the state of the sensor."""
971 assert self.
datadatadata.system_net_consumption_phases
974 system_net_consumption := self.
datadatadata.system_net_consumption_phases[
983 """Envoy net consumption CT entity."""
985 entity_description: EnvoyCTSensorEntityDescription
990 ) -> int | float | str | CtType | CtMeterStatus | CtStatusFlags | None:
991 """Return the state of the CT sensor."""
992 if (ctmeter := self.
datadatadata.ctmeter_consumption)
is None:
998 """Envoy net consumption CT phase entity."""
1000 entity_description: EnvoyCTSensorEntityDescription
1005 ) -> int | float | str | CtType | CtMeterStatus | CtStatusFlags | None:
1006 """Return the state of the CT phase sensor."""
1009 if (ctmeter := self.
datadatadata.ctmeter_consumption_phases)
is None:
1017 """Envoy net consumption CT entity."""
1019 entity_description: EnvoyCTSensorEntityDescription
1024 ) -> int | float | str | CtType | CtMeterStatus | CtStatusFlags | None:
1025 """Return the state of the CT sensor."""
1026 if (ctmeter := self.
datadatadata.ctmeter_production)
is None:
1032 """Envoy net consumption CT phase entity."""
1034 entity_description: EnvoyCTSensorEntityDescription
1039 ) -> int | float | str | CtType | CtMeterStatus | CtStatusFlags | None:
1040 """Return the state of the CT phase sensor."""
1043 if (ctmeter := self.
datadatadata.ctmeter_production_phases)
is None:
1051 """Envoy net storage CT entity."""
1053 entity_description: EnvoyCTSensorEntityDescription
1058 ) -> int | float | str | CtType | CtMeterStatus | CtStatusFlags | None:
1059 """Return the state of the CT sensor."""
1060 if (ctmeter := self.
datadatadata.ctmeter_storage)
is None:
1066 """Envoy net storage CT phase entity."""
1068 entity_description: EnvoyCTSensorEntityDescription
1073 ) -> int | float | str | CtType | CtMeterStatus | CtStatusFlags | None:
1074 """Return the state of the CT phase sensor."""
1077 if (ctmeter := self.
datadatadata.ctmeter_storage_phases)
is None:
1085 """Envoy inverter entity."""
1088 entity_description: EnvoyInverterSensorEntityDescription
1092 coordinator: EnphaseUpdateCoordinator,
1093 description: EnvoyInverterSensorEntityDescription,
1096 """Initialize Envoy inverter entity."""
1097 super().
__init__(coordinator, description)
1099 key = description.key
1100 if key == INVERTERS_KEY:
1109 identifiers={(DOMAIN, serial_number)},
1110 name=f
"Inverter {serial_number}",
1111 manufacturer=
"Enphase",
1118 """Return the state of the sensor."""
1119 inverters = self.
datadatadata.inverters
1120 assert inverters
is not None
1126 "Inverter %s not in returned inverters array (size: %s)",
1135 """Envoy Encharge sensor entity."""
1139 coordinator: EnphaseUpdateCoordinator,
1140 description: EnvoyEnchargeSensorEntityDescription
1141 | EnvoyEnchargePowerSensorEntityDescription,
1144 """Initialize Encharge entity."""
1145 super().
__init__(coordinator, description)
1148 encharge_inventory = self.
datadatadata.encharge_inventory
1149 assert encharge_inventory
is not None
1151 identifiers={(DOMAIN, serial_number)},
1152 manufacturer=
"Enphase",
1154 name=f
"Encharge {serial_number}",
1155 sw_version=
str(encharge_inventory[self.
_serial_number_serial_number].firmware_version),
1161 """Envoy Encharge inventory entity."""
1163 entity_description: EnvoyEnchargeSensorEntityDescription
1167 """Return the state of the inventory sensors."""
1168 encharge_inventory = self.
datadatadata.encharge_inventory
1169 assert encharge_inventory
is not None
1174 """Envoy Encharge power entity."""
1176 entity_description: EnvoyEnchargePowerSensorEntityDescription
1180 """Return the state of the power sensors."""
1181 encharge_power = self.
datadatadata.encharge_power
1182 assert encharge_power
is not None
1187 """Envoy Encharge Aggregate sensor entity."""
1189 entity_description: EnvoyEnchargeAggregateSensorEntityDescription
1193 """Return the state of the aggregate sensors."""
1194 encharge_aggregate = self.
datadatadata.encharge_aggregate
1195 assert encharge_aggregate
is not None
1200 """Envoy Enpower sensor entity."""
1202 entity_description: EnvoyEnpowerSensorEntityDescription
1206 coordinator: EnphaseUpdateCoordinator,
1207 description: EnvoyEnpowerSensorEntityDescription,
1209 """Initialize Enpower entity."""
1210 super().
__init__(coordinator, description)
1211 enpower_data = self.
datadatadata.enpower
1212 assert enpower_data
is not None
1215 identifiers={(DOMAIN, enpower_data.serial_number)},
1216 manufacturer=
"Enphase",
1218 name=f
"Enpower {enpower_data.serial_number}",
1219 sw_version=
str(enpower_data.firmware_version),
1225 """Return the state of the power sensors."""
1226 enpower = self.
datadatadata.enpower
1227 assert enpower
is not None
int|float|str|CtType|CtMeterStatus|CtStatusFlags|None native_value(self)
int|float|str|CtType|CtMeterStatus|CtStatusFlags|None native_value(self)
int|None native_value(self)
int|None native_value(self)
None __init__(self, EnphaseUpdateCoordinator coordinator, EnvoyEnchargeSensorEntityDescription|EnvoyEnchargePowerSensorEntityDescription description, str serial_number)
int|float|datetime.datetime|None native_value(self)
int|float|None native_value(self)
datetime.datetime|int|float|None native_value(self)
None __init__(self, EnphaseUpdateCoordinator coordinator, EnvoyEnpowerSensorEntityDescription description)
datetime.datetime|float|None native_value(self)
None __init__(self, EnphaseUpdateCoordinator coordinator, EnvoyInverterSensorEntityDescription description, str serial_number)
int|None native_value(self)
int|None native_value(self)
int|float|str|CtType|CtMeterStatus|CtStatusFlags|None native_value(self)
int|float|str|CtType|CtMeterStatus|CtStatusFlags|None native_value(self)
int|None native_value(self)
int|None native_value(self)
int|float|str|CtType|CtMeterStatus|CtStatusFlags|None native_value(self)
int|float|str|CtType|CtMeterStatus|CtStatusFlags|None native_value(self)
None __init__(self, EnphaseUpdateCoordinator coordinator, SensorEntityDescription description)
None async_setup_entry(HomeAssistant hass, EnphaseConfigEntry config_entry, AddEntitiesCallback async_add_entities)