mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Code quality improvements to PECO (#70301)
This commit is contained in:
parent
b7c1fbc842
commit
1fb261cdc5
@ -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."""
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user