mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +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
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from dataclasses import dataclass
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from typing import Final
|
from typing import Final
|
||||||
|
|
||||||
@ -18,17 +19,13 @@ from .const import CONF_COUNTY, DOMAIN, LOGGER, SCAN_INTERVAL
|
|||||||
PLATFORMS: Final = [Platform.SENSOR]
|
PLATFORMS: Final = [Platform.SENSOR]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
class PECOCoordinatorData:
|
class PECOCoordinatorData:
|
||||||
"""Something to hold the data for PECO."""
|
"""Something to hold the data for PECO."""
|
||||||
|
|
||||||
outages: OutageResults
|
outages: OutageResults
|
||||||
alerts: AlertResults
|
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:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up PECO Outage Counter from a config entry."""
|
"""Set up PECO Outage Counter from a config entry."""
|
||||||
|
@ -45,6 +45,8 @@ SENSOR_LIST: tuple[PECOSensorEntityDescription, ...] = (
|
|||||||
name="Customers Out",
|
name="Customers Out",
|
||||||
value_fn=lambda data: int(data.outages.customers_out),
|
value_fn=lambda data: int(data.outages.customers_out),
|
||||||
attribute_fn=lambda data: {},
|
attribute_fn=lambda data: {},
|
||||||
|
icon="mdi:power-plug-off",
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
PECOSensorEntityDescription(
|
PECOSensorEntityDescription(
|
||||||
key="percent_customers_out",
|
key="percent_customers_out",
|
||||||
@ -52,24 +54,31 @@ SENSOR_LIST: tuple[PECOSensorEntityDescription, ...] = (
|
|||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
value_fn=lambda data: int(data.outages.percent_customers_out),
|
value_fn=lambda data: int(data.outages.percent_customers_out),
|
||||||
attribute_fn=lambda data: {},
|
attribute_fn=lambda data: {},
|
||||||
|
icon="mdi:power-plug-off",
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
PECOSensorEntityDescription(
|
PECOSensorEntityDescription(
|
||||||
key="outage_count",
|
key="outage_count",
|
||||||
name="Outage Count",
|
name="Outage Count",
|
||||||
value_fn=lambda data: int(data.outages.outage_count),
|
value_fn=lambda data: int(data.outages.outage_count),
|
||||||
attribute_fn=lambda data: {},
|
attribute_fn=lambda data: {},
|
||||||
|
icon="mdi:power-plug-off",
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
PECOSensorEntityDescription(
|
PECOSensorEntityDescription(
|
||||||
key="customers_served",
|
key="customers_served",
|
||||||
name="Customers Served",
|
name="Customers Served",
|
||||||
value_fn=lambda data: int(data.outages.customers_served),
|
value_fn=lambda data: int(data.outages.customers_served),
|
||||||
attribute_fn=lambda data: {},
|
attribute_fn=lambda data: {},
|
||||||
|
icon="mdi:power-plug-off",
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
PECOSensorEntityDescription(
|
PECOSensorEntityDescription(
|
||||||
key="map_alert",
|
key="map_alert",
|
||||||
name="Map Alert",
|
name="Map Alert",
|
||||||
value_fn=lambda data: str(data.alerts.alert_title),
|
value_fn=lambda data: str(data.alerts.alert_title),
|
||||||
attribute_fn=lambda data: {ATTR_CONTENT: data.alerts.alert_content},
|
attribute_fn=lambda data: {ATTR_CONTENT: data.alerts.alert_content},
|
||||||
|
icon="mdi:alert",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -107,11 +116,6 @@ class PecoSensor(
|
|||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._attr_name = f"{county.capitalize()} {description.name}"
|
self._attr_name = f"{county.capitalize()} {description.name}"
|
||||||
self._attr_unique_id = f"{county}-{description.key}"
|
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
|
self.entity_description = description
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
x
Reference in New Issue
Block a user