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

Retain production values after communication with inverter is lost #180

Merged
merged 1 commit into from
Nov 26, 2024
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
40 changes: 27 additions & 13 deletions custom_components/enphase_envoy/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""The enphase_envoy component."""

from dataclasses import dataclass
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntityDescription,
Expand Down Expand Up @@ -76,6 +77,11 @@
STORAGE_MODES = ["backup", "self-consumption", "savings-mode", "economy"]


@dataclass
class InverterSensorEntityDescription(SensorEntityDescription):
retain: bool = False


def resolve_product_mapping(product_id):
return PRODUCT_ID_MAPPING.get(product_id.rsplit("-", 1)[0])

Expand Down Expand Up @@ -143,7 +149,7 @@ def get_model_name(model, hardware_id):
device_class=SensorDeviceClass.ENERGY,
suggested_display_precision=0,
),
SensorEntityDescription(
InverterSensorEntityDescription(
key="inverter_data_dc_current",
name="DC Current",
icon="mdi:current-dc",
Expand All @@ -152,87 +158,93 @@ def get_model_name(model, hardware_id):
device_class=SensorDeviceClass.CURRENT,
suggested_display_precision=3,
),
SensorEntityDescription(
InverterSensorEntityDescription(
key="inverter_data_ac_frequency",
name="AC Frequency",
native_unit_of_measurement=UnitOfFrequency.HERTZ,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.FREQUENCY,
suggested_display_precision=3,
),
SensorEntityDescription(
InverterSensorEntityDescription(
key="inverter_data_watts",
name="Production",
native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.POWER,
suggested_display_precision=0,
retain=True,
),
SensorEntityDescription(
InverterSensorEntityDescription(
key="inverter_data_ac_voltage",
name="AC Voltage",
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.VOLTAGE,
suggested_display_precision=3,
),
SensorEntityDescription(
InverterSensorEntityDescription(
key="inverter_data_dc_voltage",
name="DC Voltage",
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.VOLTAGE,
suggested_display_precision=3,
),
SensorEntityDescription(
InverterSensorEntityDescription(
key="inverter_data_temperature",
name="Temperature",
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.TEMPERATURE,
suggested_display_precision=0,
),
SensorEntityDescription(
InverterSensorEntityDescription(
key="inverter_data_lifetime_power",
name="Lifetime Energy Production",
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
suggested_display_precision=0,
retain=True,
),
SensorEntityDescription(
InverterSensorEntityDescription(
key="inverter_data_watt_hours_today",
name="Today's Energy Production",
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
state_class=SensorStateClass.TOTAL,
device_class=SensorDeviceClass.ENERGY,
suggested_display_precision=0,
retain=True,
),
SensorEntityDescription(
InverterSensorEntityDescription(
key="inverter_data_watt_hours_yesterday",
name="Yesterday's Energy Production",
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
state_class=SensorStateClass.TOTAL,
device_class=SensorDeviceClass.ENERGY,
suggested_display_precision=0,
retain=True,
),
SensorEntityDescription(
InverterSensorEntityDescription(
key="inverter_data_watt_hours_week",
name="This Week's Energy Production",
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
state_class=SensorStateClass.TOTAL,
device_class=SensorDeviceClass.ENERGY,
suggested_display_precision=0,
retain=True,
),
SensorEntityDescription(
InverterSensorEntityDescription(
key="inverter_data_last_reading",
name="Last Reading",
native_unit_of_measurement=None,
state_class=None,
device_class=SensorDeviceClass.TIMESTAMP,
entity_category=EntityCategory.DIAGNOSTIC,
retain=True,
),
SensorEntityDescription(
InverterSensorEntityDescription(
key="inverter_data_conversion_error_cycles",
name="Power Conversion Error Cycles",
native_unit_of_measurement=None,
Expand All @@ -241,15 +253,17 @@ def get_model_name(model, hardware_id):
suggested_display_precision=0,
entity_category=EntityCategory.DIAGNOSTIC,
icon="mdi:counter",
retain=True,
),
SensorEntityDescription(
InverterSensorEntityDescription(
key="inverter_data_conversion_error",
name="Power Conversion Error Seconds",
native_unit_of_measurement=UnitOfTime.SECONDS,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.DURATION,
suggested_display_precision=0,
entity_category=EntityCategory.DIAGNOSTIC,
retain=True,
),
SensorEntityDescription(
key="batteries_power",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/enphase_envoy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def native_value(self):
return datetime.datetime.fromtimestamp(
int(value), tz=datetime.timezone.utc
)
if serial.get("gone", True):
if serial.get("gone", True) and not self.entity_description.retain:
return None
return value
elif self.entity_description.key.startswith("inverter_info_"):
Expand Down
Loading