From 15c52e67a0bce156c4ba6c5c31de95b41a5e8bdb Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Sat, 22 Jul 2023 16:59:15 +0200 Subject: [PATCH] Clean up Enphase Envoy const file (#95536) --- .../components/enphase_envoy/__init__.py | 3 +- .../components/enphase_envoy/const.py | 64 +------------------ .../components/enphase_envoy/sensor.py | 61 +++++++++++++++++- 3 files changed, 62 insertions(+), 66 deletions(-) diff --git a/homeassistant/components/enphase_envoy/__init__.py b/homeassistant/components/enphase_envoy/__init__.py index 147eddacf81..1a4feb59376 100644 --- a/homeassistant/components/enphase_envoy/__init__.py +++ b/homeassistant/components/enphase_envoy/__init__.py @@ -16,7 +16,8 @@ from homeassistant.helpers import device_registry as dr from homeassistant.helpers.httpx_client import get_async_client from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed -from .const import COORDINATOR, DOMAIN, NAME, PLATFORMS, SENSORS +from .const import COORDINATOR, DOMAIN, NAME, PLATFORMS +from .sensor import SENSORS SCAN_INTERVAL = timedelta(seconds=60) diff --git a/homeassistant/components/enphase_envoy/const.py b/homeassistant/components/enphase_envoy/const.py index 4a105e5a067..e7c0b7f2a5e 100644 --- a/homeassistant/components/enphase_envoy/const.py +++ b/homeassistant/components/enphase_envoy/const.py @@ -1,10 +1,5 @@ """The enphase_envoy component.""" -from homeassistant.components.sensor import ( - SensorDeviceClass, - SensorEntityDescription, - SensorStateClass, -) -from homeassistant.const import Platform, UnitOfEnergy, UnitOfPower +from homeassistant.const import Platform DOMAIN = "enphase_envoy" @@ -13,60 +8,3 @@ PLATFORMS = [Platform.SENSOR] COORDINATOR = "coordinator" NAME = "name" - -SENSORS = ( - SensorEntityDescription( - key="production", - name="Current Power Production", - native_unit_of_measurement=UnitOfPower.WATT, - state_class=SensorStateClass.MEASUREMENT, - device_class=SensorDeviceClass.POWER, - ), - SensorEntityDescription( - key="daily_production", - name="Today's Energy Production", - native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, - state_class=SensorStateClass.TOTAL_INCREASING, - device_class=SensorDeviceClass.ENERGY, - ), - SensorEntityDescription( - key="seven_days_production", - name="Last Seven Days Energy Production", - native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, - device_class=SensorDeviceClass.ENERGY, - ), - SensorEntityDescription( - key="lifetime_production", - name="Lifetime Energy Production", - native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, - state_class=SensorStateClass.TOTAL_INCREASING, - device_class=SensorDeviceClass.ENERGY, - ), - SensorEntityDescription( - key="consumption", - name="Current Power Consumption", - native_unit_of_measurement=UnitOfPower.WATT, - state_class=SensorStateClass.MEASUREMENT, - device_class=SensorDeviceClass.POWER, - ), - SensorEntityDescription( - key="daily_consumption", - name="Today's Energy Consumption", - native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, - state_class=SensorStateClass.TOTAL_INCREASING, - device_class=SensorDeviceClass.ENERGY, - ), - SensorEntityDescription( - key="seven_days_consumption", - name="Last Seven Days Energy Consumption", - native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, - device_class=SensorDeviceClass.ENERGY, - ), - SensorEntityDescription( - key="lifetime_consumption", - name="Lifetime Energy Consumption", - native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, - state_class=SensorStateClass.TOTAL_INCREASING, - device_class=SensorDeviceClass.ENERGY, - ), -) diff --git a/homeassistant/components/enphase_envoy/sensor.py b/homeassistant/components/enphase_envoy/sensor.py index 44ffbcdb497..f42c8d94ea2 100644 --- a/homeassistant/components/enphase_envoy/sensor.py +++ b/homeassistant/components/enphase_envoy/sensor.py @@ -14,7 +14,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import UnitOfPower +from homeassistant.const import UnitOfEnergy, UnitOfPower from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -25,7 +25,7 @@ from homeassistant.helpers.update_coordinator import ( ) from homeassistant.util import dt as dt_util -from .const import COORDINATOR, DOMAIN, NAME, SENSORS +from .const import COORDINATOR, DOMAIN, NAME ICON = "mdi:flash" _LOGGER = logging.getLogger(__name__) @@ -75,6 +75,63 @@ INVERTER_SENSORS = ( ), ) +SENSORS = ( + SensorEntityDescription( + key="production", + name="Current Power Production", + native_unit_of_measurement=UnitOfPower.WATT, + state_class=SensorStateClass.MEASUREMENT, + device_class=SensorDeviceClass.POWER, + ), + SensorEntityDescription( + key="daily_production", + name="Today's Energy Production", + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, + state_class=SensorStateClass.TOTAL_INCREASING, + device_class=SensorDeviceClass.ENERGY, + ), + SensorEntityDescription( + key="seven_days_production", + name="Last Seven Days Energy Production", + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, + device_class=SensorDeviceClass.ENERGY, + ), + SensorEntityDescription( + key="lifetime_production", + name="Lifetime Energy Production", + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, + state_class=SensorStateClass.TOTAL_INCREASING, + device_class=SensorDeviceClass.ENERGY, + ), + SensorEntityDescription( + key="consumption", + name="Current Power Consumption", + native_unit_of_measurement=UnitOfPower.WATT, + state_class=SensorStateClass.MEASUREMENT, + device_class=SensorDeviceClass.POWER, + ), + SensorEntityDescription( + key="daily_consumption", + name="Today's Energy Consumption", + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, + state_class=SensorStateClass.TOTAL_INCREASING, + device_class=SensorDeviceClass.ENERGY, + ), + SensorEntityDescription( + key="seven_days_consumption", + name="Last Seven Days Energy Consumption", + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, + device_class=SensorDeviceClass.ENERGY, + ), + SensorEntityDescription( + key="lifetime_consumption", + name="Lifetime Energy Consumption", + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, + state_class=SensorStateClass.TOTAL_INCREASING, + device_class=SensorDeviceClass.ENERGY, + ), +) + async def async_setup_entry( hass: HomeAssistant,