core/homeassistant/components/peco/sensor.py

106 lines
3.0 KiB
Python
Raw Normal View History

Add PECO power outage counter integration (#65194) * Create a new NWS Alerts integration * Create a new NWS Alerts integration * Create new PECO integration * Remove empty keys * Revert "Create a new NWS Alerts integration" This reverts commit 38309c5a878d78f26df56a62e56cb602d9dc9a9e. * Revert "Create a new NWS Alerts integration" This reverts commit aeabdd37b86c370bdb8009e885806bdac6e464d8. * Fix test with new mock data * Add init and sensor to .coveragerc and more tests for config flow * Small fixes and replacing patch with pytest.raises in testing invalid county * Add type defs and fix test_config_flow to use MultipleValid instead * Fix issues with 'typing.Dict' * Move API communication to seperate PyPI library * Switch PyPI library from httpx to aiohttp to allow for passing in websessions * Commit file changes requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/d267e4300a4d359d88ef33e43b66d0e961ac154d * Add suggestions requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/586d8ffa42d7860d91e25fb82b2d6eace6645a82 * Move native_unit_of_measurement from prop to attr * Update PLATFORMS constant type annotation Co-authored-by: Matthias Alphart <farmio@alphart.net> * Add peco to .strict-typing I am from school so I can't run mypy atm * Forgot to import Final * Do as requested [here](https://github.com/home-assistant/core/runs/5070634928?check_suite_focus=true) * Updated mypy.ini, checks should pass now * Fix to conform to mypy restrictions https://github.com/home-assistant/core/runs/5072861837\?check_suite_focus\=true * Fix type annotations * Fix tests * Use cast in async_update_data * Add data type to CoordinatorEntity and DataUpdateCoordinator * More cleanup from suggestions here: https://github.com/home-assistant/core/pull/65194\#pullrequestreview-908183493 * Fix tests for new code * Cleaning up a speck of dust * Remove unused variable from the peco sensor * Add rounding to percentage, and extra clean-up * Final suggestions from @farmio * Update SCAN_INTERVAL to be a little bit faster * Change the SCAN_INTERVAL to be somewhat near the update interval of the outage map, as noted by farmio * New UpdateCoordinator typing
2022-03-21 22:56:53 +00:00
"""Sensor component for PECO outage counter."""
from __future__ import annotations
from collections.abc import Callable
from dataclasses import dataclass
from typing import Final
Add PECO power outage counter integration (#65194) * Create a new NWS Alerts integration * Create a new NWS Alerts integration * Create new PECO integration * Remove empty keys * Revert "Create a new NWS Alerts integration" This reverts commit 38309c5a878d78f26df56a62e56cb602d9dc9a9e. * Revert "Create a new NWS Alerts integration" This reverts commit aeabdd37b86c370bdb8009e885806bdac6e464d8. * Fix test with new mock data * Add init and sensor to .coveragerc and more tests for config flow * Small fixes and replacing patch with pytest.raises in testing invalid county * Add type defs and fix test_config_flow to use MultipleValid instead * Fix issues with 'typing.Dict' * Move API communication to seperate PyPI library * Switch PyPI library from httpx to aiohttp to allow for passing in websessions * Commit file changes requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/d267e4300a4d359d88ef33e43b66d0e961ac154d * Add suggestions requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/586d8ffa42d7860d91e25fb82b2d6eace6645a82 * Move native_unit_of_measurement from prop to attr * Update PLATFORMS constant type annotation Co-authored-by: Matthias Alphart <farmio@alphart.net> * Add peco to .strict-typing I am from school so I can't run mypy atm * Forgot to import Final * Do as requested [here](https://github.com/home-assistant/core/runs/5070634928?check_suite_focus=true) * Updated mypy.ini, checks should pass now * Fix to conform to mypy restrictions https://github.com/home-assistant/core/runs/5072861837\?check_suite_focus\=true * Fix type annotations * Fix tests * Use cast in async_update_data * Add data type to CoordinatorEntity and DataUpdateCoordinator * More cleanup from suggestions here: https://github.com/home-assistant/core/pull/65194\#pullrequestreview-908183493 * Fix tests for new code * Cleaning up a speck of dust * Remove unused variable from the peco sensor * Add rounding to percentage, and extra clean-up * Final suggestions from @farmio * Update SCAN_INTERVAL to be a little bit faster * Change the SCAN_INTERVAL to be somewhat near the update interval of the outage map, as noted by farmio * New UpdateCoordinator typing
2022-03-21 22:56:53 +00:00
from peco import OutageResults
Add PECO power outage counter integration (#65194) * Create a new NWS Alerts integration * Create a new NWS Alerts integration * Create new PECO integration * Remove empty keys * Revert "Create a new NWS Alerts integration" This reverts commit 38309c5a878d78f26df56a62e56cb602d9dc9a9e. * Revert "Create a new NWS Alerts integration" This reverts commit aeabdd37b86c370bdb8009e885806bdac6e464d8. * Fix test with new mock data * Add init and sensor to .coveragerc and more tests for config flow * Small fixes and replacing patch with pytest.raises in testing invalid county * Add type defs and fix test_config_flow to use MultipleValid instead * Fix issues with 'typing.Dict' * Move API communication to seperate PyPI library * Switch PyPI library from httpx to aiohttp to allow for passing in websessions * Commit file changes requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/d267e4300a4d359d88ef33e43b66d0e961ac154d * Add suggestions requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/586d8ffa42d7860d91e25fb82b2d6eace6645a82 * Move native_unit_of_measurement from prop to attr * Update PLATFORMS constant type annotation Co-authored-by: Matthias Alphart <farmio@alphart.net> * Add peco to .strict-typing I am from school so I can't run mypy atm * Forgot to import Final * Do as requested [here](https://github.com/home-assistant/core/runs/5070634928?check_suite_focus=true) * Updated mypy.ini, checks should pass now * Fix to conform to mypy restrictions https://github.com/home-assistant/core/runs/5072861837\?check_suite_focus\=true * Fix type annotations * Fix tests * Use cast in async_update_data * Add data type to CoordinatorEntity and DataUpdateCoordinator * More cleanup from suggestions here: https://github.com/home-assistant/core/pull/65194\#pullrequestreview-908183493 * Fix tests for new code * Cleaning up a speck of dust * Remove unused variable from the peco sensor * Add rounding to percentage, and extra clean-up * Final suggestions from @farmio * Update SCAN_INTERVAL to be a little bit faster * Change the SCAN_INTERVAL to be somewhat near the update interval of the outage map, as noted by farmio * New UpdateCoordinator typing
2022-03-21 22:56:53 +00:00
from homeassistant.components.sensor import (
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PERCENTAGE
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
)
from .const import CONF_COUNTY, DOMAIN
Add PECO power outage counter integration (#65194) * Create a new NWS Alerts integration * Create a new NWS Alerts integration * Create new PECO integration * Remove empty keys * Revert "Create a new NWS Alerts integration" This reverts commit 38309c5a878d78f26df56a62e56cb602d9dc9a9e. * Revert "Create a new NWS Alerts integration" This reverts commit aeabdd37b86c370bdb8009e885806bdac6e464d8. * Fix test with new mock data * Add init and sensor to .coveragerc and more tests for config flow * Small fixes and replacing patch with pytest.raises in testing invalid county * Add type defs and fix test_config_flow to use MultipleValid instead * Fix issues with 'typing.Dict' * Move API communication to seperate PyPI library * Switch PyPI library from httpx to aiohttp to allow for passing in websessions * Commit file changes requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/d267e4300a4d359d88ef33e43b66d0e961ac154d * Add suggestions requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/586d8ffa42d7860d91e25fb82b2d6eace6645a82 * Move native_unit_of_measurement from prop to attr * Update PLATFORMS constant type annotation Co-authored-by: Matthias Alphart <farmio@alphart.net> * Add peco to .strict-typing I am from school so I can't run mypy atm * Forgot to import Final * Do as requested [here](https://github.com/home-assistant/core/runs/5070634928?check_suite_focus=true) * Updated mypy.ini, checks should pass now * Fix to conform to mypy restrictions https://github.com/home-assistant/core/runs/5072861837\?check_suite_focus\=true * Fix type annotations * Fix tests * Use cast in async_update_data * Add data type to CoordinatorEntity and DataUpdateCoordinator * More cleanup from suggestions here: https://github.com/home-assistant/core/pull/65194\#pullrequestreview-908183493 * Fix tests for new code * Cleaning up a speck of dust * Remove unused variable from the peco sensor * Add rounding to percentage, and extra clean-up * Final suggestions from @farmio * Update SCAN_INTERVAL to be a little bit faster * Change the SCAN_INTERVAL to be somewhat near the update interval of the outage map, as noted by farmio * New UpdateCoordinator typing
2022-03-21 22:56:53 +00:00
@dataclass
class PECOSensorEntityDescriptionMixin:
"""Mixin for required keys."""
value_fn: Callable[[OutageResults], int]
@dataclass
class PECOSensorEntityDescription(
SensorEntityDescription, PECOSensorEntityDescriptionMixin
):
"""Description for PECO sensor."""
Add PECO power outage counter integration (#65194) * Create a new NWS Alerts integration * Create a new NWS Alerts integration * Create new PECO integration * Remove empty keys * Revert "Create a new NWS Alerts integration" This reverts commit 38309c5a878d78f26df56a62e56cb602d9dc9a9e. * Revert "Create a new NWS Alerts integration" This reverts commit aeabdd37b86c370bdb8009e885806bdac6e464d8. * Fix test with new mock data * Add init and sensor to .coveragerc and more tests for config flow * Small fixes and replacing patch with pytest.raises in testing invalid county * Add type defs and fix test_config_flow to use MultipleValid instead * Fix issues with 'typing.Dict' * Move API communication to seperate PyPI library * Switch PyPI library from httpx to aiohttp to allow for passing in websessions * Commit file changes requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/d267e4300a4d359d88ef33e43b66d0e961ac154d * Add suggestions requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/586d8ffa42d7860d91e25fb82b2d6eace6645a82 * Move native_unit_of_measurement from prop to attr * Update PLATFORMS constant type annotation Co-authored-by: Matthias Alphart <farmio@alphart.net> * Add peco to .strict-typing I am from school so I can't run mypy atm * Forgot to import Final * Do as requested [here](https://github.com/home-assistant/core/runs/5070634928?check_suite_focus=true) * Updated mypy.ini, checks should pass now * Fix to conform to mypy restrictions https://github.com/home-assistant/core/runs/5072861837\?check_suite_focus\=true * Fix type annotations * Fix tests * Use cast in async_update_data * Add data type to CoordinatorEntity and DataUpdateCoordinator * More cleanup from suggestions here: https://github.com/home-assistant/core/pull/65194\#pullrequestreview-908183493 * Fix tests for new code * Cleaning up a speck of dust * Remove unused variable from the peco sensor * Add rounding to percentage, and extra clean-up * Final suggestions from @farmio * Update SCAN_INTERVAL to be a little bit faster * Change the SCAN_INTERVAL to be somewhat near the update interval of the outage map, as noted by farmio * New UpdateCoordinator typing
2022-03-21 22:56:53 +00:00
PARALLEL_UPDATES: Final = 0
SENSOR_LIST: tuple[PECOSensorEntityDescription, ...] = (
PECOSensorEntityDescription(
key="customers_out",
name="Customers Out",
value_fn=lambda data: int(data.customers_out),
),
PECOSensorEntityDescription(
Add PECO power outage counter integration (#65194) * Create a new NWS Alerts integration * Create a new NWS Alerts integration * Create new PECO integration * Remove empty keys * Revert "Create a new NWS Alerts integration" This reverts commit 38309c5a878d78f26df56a62e56cb602d9dc9a9e. * Revert "Create a new NWS Alerts integration" This reverts commit aeabdd37b86c370bdb8009e885806bdac6e464d8. * Fix test with new mock data * Add init and sensor to .coveragerc and more tests for config flow * Small fixes and replacing patch with pytest.raises in testing invalid county * Add type defs and fix test_config_flow to use MultipleValid instead * Fix issues with 'typing.Dict' * Move API communication to seperate PyPI library * Switch PyPI library from httpx to aiohttp to allow for passing in websessions * Commit file changes requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/d267e4300a4d359d88ef33e43b66d0e961ac154d * Add suggestions requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/586d8ffa42d7860d91e25fb82b2d6eace6645a82 * Move native_unit_of_measurement from prop to attr * Update PLATFORMS constant type annotation Co-authored-by: Matthias Alphart <farmio@alphart.net> * Add peco to .strict-typing I am from school so I can't run mypy atm * Forgot to import Final * Do as requested [here](https://github.com/home-assistant/core/runs/5070634928?check_suite_focus=true) * Updated mypy.ini, checks should pass now * Fix to conform to mypy restrictions https://github.com/home-assistant/core/runs/5072861837\?check_suite_focus\=true * Fix type annotations * Fix tests * Use cast in async_update_data * Add data type to CoordinatorEntity and DataUpdateCoordinator * More cleanup from suggestions here: https://github.com/home-assistant/core/pull/65194\#pullrequestreview-908183493 * Fix tests for new code * Cleaning up a speck of dust * Remove unused variable from the peco sensor * Add rounding to percentage, and extra clean-up * Final suggestions from @farmio * Update SCAN_INTERVAL to be a little bit faster * Change the SCAN_INTERVAL to be somewhat near the update interval of the outage map, as noted by farmio * New UpdateCoordinator typing
2022-03-21 22:56:53 +00:00
key="percent_customers_out",
name="Percent Customers Out",
native_unit_of_measurement=PERCENTAGE,
value_fn=lambda data: int(data.percent_customers_out),
),
PECOSensorEntityDescription(
key="outage_count",
name="Outage Count",
value_fn=lambda data: int(data.outage_count),
),
PECOSensorEntityDescription(
key="customers_served",
name="Customers Served",
value_fn=lambda data: int(data.customers_served),
Add PECO power outage counter integration (#65194) * Create a new NWS Alerts integration * Create a new NWS Alerts integration * Create new PECO integration * Remove empty keys * Revert "Create a new NWS Alerts integration" This reverts commit 38309c5a878d78f26df56a62e56cb602d9dc9a9e. * Revert "Create a new NWS Alerts integration" This reverts commit aeabdd37b86c370bdb8009e885806bdac6e464d8. * Fix test with new mock data * Add init and sensor to .coveragerc and more tests for config flow * Small fixes and replacing patch with pytest.raises in testing invalid county * Add type defs and fix test_config_flow to use MultipleValid instead * Fix issues with 'typing.Dict' * Move API communication to seperate PyPI library * Switch PyPI library from httpx to aiohttp to allow for passing in websessions * Commit file changes requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/d267e4300a4d359d88ef33e43b66d0e961ac154d * Add suggestions requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/586d8ffa42d7860d91e25fb82b2d6eace6645a82 * Move native_unit_of_measurement from prop to attr * Update PLATFORMS constant type annotation Co-authored-by: Matthias Alphart <farmio@alphart.net> * Add peco to .strict-typing I am from school so I can't run mypy atm * Forgot to import Final * Do as requested [here](https://github.com/home-assistant/core/runs/5070634928?check_suite_focus=true) * Updated mypy.ini, checks should pass now * Fix to conform to mypy restrictions https://github.com/home-assistant/core/runs/5072861837\?check_suite_focus\=true * Fix type annotations * Fix tests * Use cast in async_update_data * Add data type to CoordinatorEntity and DataUpdateCoordinator * More cleanup from suggestions here: https://github.com/home-assistant/core/pull/65194\#pullrequestreview-908183493 * Fix tests for new code * Cleaning up a speck of dust * Remove unused variable from the peco sensor * Add rounding to percentage, and extra clean-up * Final suggestions from @farmio * Update SCAN_INTERVAL to be a little bit faster * Change the SCAN_INTERVAL to be somewhat near the update interval of the outage map, as noted by farmio * New UpdateCoordinator typing
2022-03-21 22:56:53 +00:00
),
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the sensor platform."""
county: str = config_entry.data[CONF_COUNTY]
coordinator = hass.data[DOMAIN][config_entry.entry_id]
Add PECO power outage counter integration (#65194) * Create a new NWS Alerts integration * Create a new NWS Alerts integration * Create new PECO integration * Remove empty keys * Revert "Create a new NWS Alerts integration" This reverts commit 38309c5a878d78f26df56a62e56cb602d9dc9a9e. * Revert "Create a new NWS Alerts integration" This reverts commit aeabdd37b86c370bdb8009e885806bdac6e464d8. * Fix test with new mock data * Add init and sensor to .coveragerc and more tests for config flow * Small fixes and replacing patch with pytest.raises in testing invalid county * Add type defs and fix test_config_flow to use MultipleValid instead * Fix issues with 'typing.Dict' * Move API communication to seperate PyPI library * Switch PyPI library from httpx to aiohttp to allow for passing in websessions * Commit file changes requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/d267e4300a4d359d88ef33e43b66d0e961ac154d * Add suggestions requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/586d8ffa42d7860d91e25fb82b2d6eace6645a82 * Move native_unit_of_measurement from prop to attr * Update PLATFORMS constant type annotation Co-authored-by: Matthias Alphart <farmio@alphart.net> * Add peco to .strict-typing I am from school so I can't run mypy atm * Forgot to import Final * Do as requested [here](https://github.com/home-assistant/core/runs/5070634928?check_suite_focus=true) * Updated mypy.ini, checks should pass now * Fix to conform to mypy restrictions https://github.com/home-assistant/core/runs/5072861837\?check_suite_focus\=true * Fix type annotations * Fix tests * Use cast in async_update_data * Add data type to CoordinatorEntity and DataUpdateCoordinator * More cleanup from suggestions here: https://github.com/home-assistant/core/pull/65194\#pullrequestreview-908183493 * Fix tests for new code * Cleaning up a speck of dust * Remove unused variable from the peco sensor * Add rounding to percentage, and extra clean-up * Final suggestions from @farmio * Update SCAN_INTERVAL to be a little bit faster * Change the SCAN_INTERVAL to be somewhat near the update interval of the outage map, as noted by farmio * New UpdateCoordinator typing
2022-03-21 22:56:53 +00:00
async_add_entities(
[PecoSensor(sensor, county, coordinator) for sensor in SENSOR_LIST],
True,
)
return
class PecoSensor(CoordinatorEntity[DataUpdateCoordinator[OutageResults]], SensorEntity):
Add PECO power outage counter integration (#65194) * Create a new NWS Alerts integration * Create a new NWS Alerts integration * Create new PECO integration * Remove empty keys * Revert "Create a new NWS Alerts integration" This reverts commit 38309c5a878d78f26df56a62e56cb602d9dc9a9e. * Revert "Create a new NWS Alerts integration" This reverts commit aeabdd37b86c370bdb8009e885806bdac6e464d8. * Fix test with new mock data * Add init and sensor to .coveragerc and more tests for config flow * Small fixes and replacing patch with pytest.raises in testing invalid county * Add type defs and fix test_config_flow to use MultipleValid instead * Fix issues with 'typing.Dict' * Move API communication to seperate PyPI library * Switch PyPI library from httpx to aiohttp to allow for passing in websessions * Commit file changes requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/d267e4300a4d359d88ef33e43b66d0e961ac154d * Add suggestions requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/586d8ffa42d7860d91e25fb82b2d6eace6645a82 * Move native_unit_of_measurement from prop to attr * Update PLATFORMS constant type annotation Co-authored-by: Matthias Alphart <farmio@alphart.net> * Add peco to .strict-typing I am from school so I can't run mypy atm * Forgot to import Final * Do as requested [here](https://github.com/home-assistant/core/runs/5070634928?check_suite_focus=true) * Updated mypy.ini, checks should pass now * Fix to conform to mypy restrictions https://github.com/home-assistant/core/runs/5072861837\?check_suite_focus\=true * Fix type annotations * Fix tests * Use cast in async_update_data * Add data type to CoordinatorEntity and DataUpdateCoordinator * More cleanup from suggestions here: https://github.com/home-assistant/core/pull/65194\#pullrequestreview-908183493 * Fix tests for new code * Cleaning up a speck of dust * Remove unused variable from the peco sensor * Add rounding to percentage, and extra clean-up * Final suggestions from @farmio * Update SCAN_INTERVAL to be a little bit faster * Change the SCAN_INTERVAL to be somewhat near the update interval of the outage map, as noted by farmio * New UpdateCoordinator typing
2022-03-21 22:56:53 +00:00
"""PECO outage counter sensor."""
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_icon: str = "mdi:power-plug-off"
entity_description: PECOSensorEntityDescription
Add PECO power outage counter integration (#65194) * Create a new NWS Alerts integration * Create a new NWS Alerts integration * Create new PECO integration * Remove empty keys * Revert "Create a new NWS Alerts integration" This reverts commit 38309c5a878d78f26df56a62e56cb602d9dc9a9e. * Revert "Create a new NWS Alerts integration" This reverts commit aeabdd37b86c370bdb8009e885806bdac6e464d8. * Fix test with new mock data * Add init and sensor to .coveragerc and more tests for config flow * Small fixes and replacing patch with pytest.raises in testing invalid county * Add type defs and fix test_config_flow to use MultipleValid instead * Fix issues with 'typing.Dict' * Move API communication to seperate PyPI library * Switch PyPI library from httpx to aiohttp to allow for passing in websessions * Commit file changes requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/d267e4300a4d359d88ef33e43b66d0e961ac154d * Add suggestions requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/586d8ffa42d7860d91e25fb82b2d6eace6645a82 * Move native_unit_of_measurement from prop to attr * Update PLATFORMS constant type annotation Co-authored-by: Matthias Alphart <farmio@alphart.net> * Add peco to .strict-typing I am from school so I can't run mypy atm * Forgot to import Final * Do as requested [here](https://github.com/home-assistant/core/runs/5070634928?check_suite_focus=true) * Updated mypy.ini, checks should pass now * Fix to conform to mypy restrictions https://github.com/home-assistant/core/runs/5072861837\?check_suite_focus\=true * Fix type annotations * Fix tests * Use cast in async_update_data * Add data type to CoordinatorEntity and DataUpdateCoordinator * More cleanup from suggestions here: https://github.com/home-assistant/core/pull/65194\#pullrequestreview-908183493 * Fix tests for new code * Cleaning up a speck of dust * Remove unused variable from the peco sensor * Add rounding to percentage, and extra clean-up * Final suggestions from @farmio * Update SCAN_INTERVAL to be a little bit faster * Change the SCAN_INTERVAL to be somewhat near the update interval of the outage map, as noted by farmio * New UpdateCoordinator typing
2022-03-21 22:56:53 +00:00
def __init__(
self,
description: PECOSensorEntityDescription,
Add PECO power outage counter integration (#65194) * Create a new NWS Alerts integration * Create a new NWS Alerts integration * Create new PECO integration * Remove empty keys * Revert "Create a new NWS Alerts integration" This reverts commit 38309c5a878d78f26df56a62e56cb602d9dc9a9e. * Revert "Create a new NWS Alerts integration" This reverts commit aeabdd37b86c370bdb8009e885806bdac6e464d8. * Fix test with new mock data * Add init and sensor to .coveragerc and more tests for config flow * Small fixes and replacing patch with pytest.raises in testing invalid county * Add type defs and fix test_config_flow to use MultipleValid instead * Fix issues with 'typing.Dict' * Move API communication to seperate PyPI library * Switch PyPI library from httpx to aiohttp to allow for passing in websessions * Commit file changes requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/d267e4300a4d359d88ef33e43b66d0e961ac154d * Add suggestions requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/586d8ffa42d7860d91e25fb82b2d6eace6645a82 * Move native_unit_of_measurement from prop to attr * Update PLATFORMS constant type annotation Co-authored-by: Matthias Alphart <farmio@alphart.net> * Add peco to .strict-typing I am from school so I can't run mypy atm * Forgot to import Final * Do as requested [here](https://github.com/home-assistant/core/runs/5070634928?check_suite_focus=true) * Updated mypy.ini, checks should pass now * Fix to conform to mypy restrictions https://github.com/home-assistant/core/runs/5072861837\?check_suite_focus\=true * Fix type annotations * Fix tests * Use cast in async_update_data * Add data type to CoordinatorEntity and DataUpdateCoordinator * More cleanup from suggestions here: https://github.com/home-assistant/core/pull/65194\#pullrequestreview-908183493 * Fix tests for new code * Cleaning up a speck of dust * Remove unused variable from the peco sensor * Add rounding to percentage, and extra clean-up * Final suggestions from @farmio * Update SCAN_INTERVAL to be a little bit faster * Change the SCAN_INTERVAL to be somewhat near the update interval of the outage map, as noted by farmio * New UpdateCoordinator typing
2022-03-21 22:56:53 +00:00
county: str,
coordinator: DataUpdateCoordinator[OutageResults],
Add PECO power outage counter integration (#65194) * Create a new NWS Alerts integration * Create a new NWS Alerts integration * Create new PECO integration * Remove empty keys * Revert "Create a new NWS Alerts integration" This reverts commit 38309c5a878d78f26df56a62e56cb602d9dc9a9e. * Revert "Create a new NWS Alerts integration" This reverts commit aeabdd37b86c370bdb8009e885806bdac6e464d8. * Fix test with new mock data * Add init and sensor to .coveragerc and more tests for config flow * Small fixes and replacing patch with pytest.raises in testing invalid county * Add type defs and fix test_config_flow to use MultipleValid instead * Fix issues with 'typing.Dict' * Move API communication to seperate PyPI library * Switch PyPI library from httpx to aiohttp to allow for passing in websessions * Commit file changes requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/d267e4300a4d359d88ef33e43b66d0e961ac154d * Add suggestions requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/586d8ffa42d7860d91e25fb82b2d6eace6645a82 * Move native_unit_of_measurement from prop to attr * Update PLATFORMS constant type annotation Co-authored-by: Matthias Alphart <farmio@alphart.net> * Add peco to .strict-typing I am from school so I can't run mypy atm * Forgot to import Final * Do as requested [here](https://github.com/home-assistant/core/runs/5070634928?check_suite_focus=true) * Updated mypy.ini, checks should pass now * Fix to conform to mypy restrictions https://github.com/home-assistant/core/runs/5072861837\?check_suite_focus\=true * Fix type annotations * Fix tests * Use cast in async_update_data * Add data type to CoordinatorEntity and DataUpdateCoordinator * More cleanup from suggestions here: https://github.com/home-assistant/core/pull/65194\#pullrequestreview-908183493 * Fix tests for new code * Cleaning up a speck of dust * Remove unused variable from the peco sensor * Add rounding to percentage, and extra clean-up * Final suggestions from @farmio * Update SCAN_INTERVAL to be a little bit faster * Change the SCAN_INTERVAL to be somewhat near the update interval of the outage map, as noted by farmio * New UpdateCoordinator typing
2022-03-21 22:56:53 +00:00
) -> None:
"""Initialize the sensor."""
super().__init__(coordinator)
self._attr_name = f"{county.capitalize()} {description.name}"
self._attr_unique_id = f"{county}-{description.key}"
self.entity_description = description
@property
def native_value(self) -> int:
Add PECO power outage counter integration (#65194) * Create a new NWS Alerts integration * Create a new NWS Alerts integration * Create new PECO integration * Remove empty keys * Revert "Create a new NWS Alerts integration" This reverts commit 38309c5a878d78f26df56a62e56cb602d9dc9a9e. * Revert "Create a new NWS Alerts integration" This reverts commit aeabdd37b86c370bdb8009e885806bdac6e464d8. * Fix test with new mock data * Add init and sensor to .coveragerc and more tests for config flow * Small fixes and replacing patch with pytest.raises in testing invalid county * Add type defs and fix test_config_flow to use MultipleValid instead * Fix issues with 'typing.Dict' * Move API communication to seperate PyPI library * Switch PyPI library from httpx to aiohttp to allow for passing in websessions * Commit file changes requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/d267e4300a4d359d88ef33e43b66d0e961ac154d * Add suggestions requested by farmio as listed here: https://github.com/home-assistant/core/pull/65194/files/586d8ffa42d7860d91e25fb82b2d6eace6645a82 * Move native_unit_of_measurement from prop to attr * Update PLATFORMS constant type annotation Co-authored-by: Matthias Alphart <farmio@alphart.net> * Add peco to .strict-typing I am from school so I can't run mypy atm * Forgot to import Final * Do as requested [here](https://github.com/home-assistant/core/runs/5070634928?check_suite_focus=true) * Updated mypy.ini, checks should pass now * Fix to conform to mypy restrictions https://github.com/home-assistant/core/runs/5072861837\?check_suite_focus\=true * Fix type annotations * Fix tests * Use cast in async_update_data * Add data type to CoordinatorEntity and DataUpdateCoordinator * More cleanup from suggestions here: https://github.com/home-assistant/core/pull/65194\#pullrequestreview-908183493 * Fix tests for new code * Cleaning up a speck of dust * Remove unused variable from the peco sensor * Add rounding to percentage, and extra clean-up * Final suggestions from @farmio * Update SCAN_INTERVAL to be a little bit faster * Change the SCAN_INTERVAL to be somewhat near the update interval of the outage map, as noted by farmio * New UpdateCoordinator typing
2022-03-21 22:56:53 +00:00
"""Return the value of the sensor."""
return self.entity_description.value_fn(self.coordinator.data)