From 1fb261cdc53dd1a630c643665b2f511cdad0c813 Mon Sep 17 00:00:00 2001 From: IceBotYT <34712694+IceBotYT@users.noreply.github.com> Date: Tue, 19 Apr 2022 16:45:27 -0400 Subject: [PATCH] Code quality improvements to PECO (#70301) --- homeassistant/components/peco/__init__.py | 7 ++----- homeassistant/components/peco/sensor.py | 14 +++++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/peco/__init__.py b/homeassistant/components/peco/__init__.py index b62b19006b6..6f88bf36c50 100644 --- a/homeassistant/components/peco/__init__.py +++ b/homeassistant/components/peco/__init__.py @@ -2,6 +2,7 @@ from __future__ import annotations import asyncio +from dataclasses import dataclass from datetime import timedelta from typing import Final @@ -18,17 +19,13 @@ from .const import CONF_COUNTY, DOMAIN, LOGGER, SCAN_INTERVAL PLATFORMS: Final = [Platform.SENSOR] +@dataclass class PECOCoordinatorData: """Something to hold the data for PECO.""" outages: OutageResults alerts: AlertResults - def __init__(self, outages: OutageResults, alerts: AlertResults) -> None: - """Initialize the data holder for PECO.""" - self.outages = outages - self.alerts = alerts - async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up PECO Outage Counter from a config entry.""" diff --git a/homeassistant/components/peco/sensor.py b/homeassistant/components/peco/sensor.py index 8eb67816363..dfd354f5c03 100644 --- a/homeassistant/components/peco/sensor.py +++ b/homeassistant/components/peco/sensor.py @@ -45,6 +45,8 @@ SENSOR_LIST: tuple[PECOSensorEntityDescription, ...] = ( name="Customers Out", value_fn=lambda data: int(data.outages.customers_out), attribute_fn=lambda data: {}, + icon="mdi:power-plug-off", + state_class=SensorStateClass.MEASUREMENT, ), PECOSensorEntityDescription( key="percent_customers_out", @@ -52,24 +54,31 @@ SENSOR_LIST: tuple[PECOSensorEntityDescription, ...] = ( native_unit_of_measurement=PERCENTAGE, value_fn=lambda data: int(data.outages.percent_customers_out), attribute_fn=lambda data: {}, + icon="mdi:power-plug-off", + state_class=SensorStateClass.MEASUREMENT, ), PECOSensorEntityDescription( key="outage_count", name="Outage Count", value_fn=lambda data: int(data.outages.outage_count), attribute_fn=lambda data: {}, + icon="mdi:power-plug-off", + state_class=SensorStateClass.MEASUREMENT, ), PECOSensorEntityDescription( key="customers_served", name="Customers Served", value_fn=lambda data: int(data.outages.customers_served), attribute_fn=lambda data: {}, + icon="mdi:power-plug-off", + state_class=SensorStateClass.MEASUREMENT, ), PECOSensorEntityDescription( key="map_alert", name="Map Alert", value_fn=lambda data: str(data.alerts.alert_title), attribute_fn=lambda data: {ATTR_CONTENT: data.alerts.alert_content}, + icon="mdi:alert", ), ) @@ -107,11 +116,6 @@ class PecoSensor( super().__init__(coordinator) self._attr_name = f"{county.capitalize()} {description.name}" self._attr_unique_id = f"{county}-{description.key}" - self._attr_icon = ( - "mdi:alert" if description.key == "map_alert" else "mdi:power-plug-off" - ) - if description.key != "map_alert": - self._attr_state_class = SensorStateClass.MEASUREMENT self.entity_description = description @property