mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Enable strict typing for amberelectric (#106817)
This commit is contained in:
parent
c5c132e1d4
commit
3b0d877b5e
@ -61,6 +61,7 @@ homeassistant.components.alert.*
|
|||||||
homeassistant.components.alexa.*
|
homeassistant.components.alexa.*
|
||||||
homeassistant.components.alpha_vantage.*
|
homeassistant.components.alpha_vantage.*
|
||||||
homeassistant.components.amazon_polly.*
|
homeassistant.components.amazon_polly.*
|
||||||
|
homeassistant.components.amberelectric.*
|
||||||
homeassistant.components.ambient_station.*
|
homeassistant.components.ambient_station.*
|
||||||
homeassistant.components.amcrest.*
|
homeassistant.components.amcrest.*
|
||||||
homeassistant.components.ampio.*
|
homeassistant.components.ampio.*
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Mapping
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
@ -45,14 +44,14 @@ class AmberPriceGridSensor(
|
|||||||
@property
|
@property
|
||||||
def is_on(self) -> bool | None:
|
def is_on(self) -> bool | None:
|
||||||
"""Return true if the binary sensor is on."""
|
"""Return true if the binary sensor is on."""
|
||||||
return self.coordinator.data["grid"][self.entity_description.key]
|
return self.coordinator.data["grid"][self.entity_description.key] # type: ignore[no-any-return]
|
||||||
|
|
||||||
|
|
||||||
class AmberPriceSpikeBinarySensor(AmberPriceGridSensor):
|
class AmberPriceSpikeBinarySensor(AmberPriceGridSensor):
|
||||||
"""Sensor to show single grid binary values."""
|
"""Sensor to show single grid binary values."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self) -> str:
|
||||||
"""Return the sensor icon."""
|
"""Return the sensor icon."""
|
||||||
status = self.coordinator.data["grid"]["price_spike"]
|
status = self.coordinator.data["grid"]["price_spike"]
|
||||||
return PRICE_SPIKE_ICONS[status]
|
return PRICE_SPIKE_ICONS[status]
|
||||||
@ -60,10 +59,10 @@ class AmberPriceSpikeBinarySensor(AmberPriceGridSensor):
|
|||||||
@property
|
@property
|
||||||
def is_on(self) -> bool | None:
|
def is_on(self) -> bool | None:
|
||||||
"""Return true if the binary sensor is on."""
|
"""Return true if the binary sensor is on."""
|
||||||
return self.coordinator.data["grid"]["price_spike"] == "spike"
|
return self.coordinator.data["grid"]["price_spike"] == "spike" # type: ignore[no-any-return]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> Mapping[str, Any] | None:
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return additional pieces of information about the price spike."""
|
"""Return additional pieces of information about the price spike."""
|
||||||
|
|
||||||
spike_status = self.coordinator.data["grid"]["price_spike"]
|
spike_status = self.coordinator.data["grid"]["price_spike"]
|
||||||
@ -80,10 +79,10 @@ async def async_setup_entry(
|
|||||||
"""Set up a config entry."""
|
"""Set up a config entry."""
|
||||||
coordinator: AmberUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator: AmberUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
|
||||||
entities: list = []
|
|
||||||
price_spike_description = BinarySensorEntityDescription(
|
price_spike_description = BinarySensorEntityDescription(
|
||||||
key="price_spike",
|
key="price_spike",
|
||||||
name=f"{entry.title} - Price Spike",
|
name=f"{entry.title} - Price Spike",
|
||||||
)
|
)
|
||||||
entities.append(AmberPriceSpikeBinarySensor(coordinator, price_spike_description))
|
async_add_entities(
|
||||||
async_add_entities(entities)
|
[AmberPriceSpikeBinarySensor(coordinator, price_spike_description)]
|
||||||
|
)
|
||||||
|
@ -28,10 +28,10 @@ class AmberElectricConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
def _fetch_sites(self, token: str) -> list[Site] | None:
|
def _fetch_sites(self, token: str) -> list[Site] | None:
|
||||||
configuration = amberelectric.Configuration(access_token=token)
|
configuration = amberelectric.Configuration(access_token=token)
|
||||||
api = amber_api.AmberApi.create(configuration)
|
api: amber_api.AmberApi = amber_api.AmberApi.create(configuration)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sites = api.get_sites()
|
sites: list[Site] = api.get_sites()
|
||||||
if len(sites) == 0:
|
if len(sites) == 0:
|
||||||
self._errors[CONF_API_TOKEN] = "no_site"
|
self._errors[CONF_API_TOKEN] = "no_site"
|
||||||
return None
|
return None
|
||||||
|
@ -30,19 +30,19 @@ def is_forecast(interval: ActualInterval | CurrentInterval | ForecastInterval) -
|
|||||||
|
|
||||||
def is_general(interval: ActualInterval | CurrentInterval | ForecastInterval) -> bool:
|
def is_general(interval: ActualInterval | CurrentInterval | ForecastInterval) -> bool:
|
||||||
"""Return true if the supplied interval is on the general channel."""
|
"""Return true if the supplied interval is on the general channel."""
|
||||||
return interval.channel_type == ChannelType.GENERAL
|
return interval.channel_type == ChannelType.GENERAL # type: ignore[no-any-return]
|
||||||
|
|
||||||
|
|
||||||
def is_controlled_load(
|
def is_controlled_load(
|
||||||
interval: ActualInterval | CurrentInterval | ForecastInterval,
|
interval: ActualInterval | CurrentInterval | ForecastInterval,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Return true if the supplied interval is on the controlled load channel."""
|
"""Return true if the supplied interval is on the controlled load channel."""
|
||||||
return interval.channel_type == ChannelType.CONTROLLED_LOAD
|
return interval.channel_type == ChannelType.CONTROLLED_LOAD # type: ignore[no-any-return]
|
||||||
|
|
||||||
|
|
||||||
def is_feed_in(interval: ActualInterval | CurrentInterval | ForecastInterval) -> bool:
|
def is_feed_in(interval: ActualInterval | CurrentInterval | ForecastInterval) -> bool:
|
||||||
"""Return true if the supplied interval is on the feed in channel."""
|
"""Return true if the supplied interval is on the feed in channel."""
|
||||||
return interval.channel_type == ChannelType.FEED_IN
|
return interval.channel_type == ChannelType.FEED_IN # type: ignore[no-any-return]
|
||||||
|
|
||||||
|
|
||||||
def normalize_descriptor(descriptor: Descriptor) -> str | None:
|
def normalize_descriptor(descriptor: Descriptor) -> str | None:
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Mapping
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from amberelectric.model.channel import ChannelType
|
from amberelectric.model.channel import ChannelType
|
||||||
@ -86,7 +85,7 @@ class AmberPriceSensor(AmberSensor):
|
|||||||
return format_cents_to_dollars(interval.per_kwh)
|
return format_cents_to_dollars(interval.per_kwh)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> Mapping[str, Any] | None:
|
def extra_state_attributes(self) -> dict[str, Any] | None:
|
||||||
"""Return additional pieces of information about the price."""
|
"""Return additional pieces of information about the price."""
|
||||||
interval = self.coordinator.data[self.entity_description.key][self.channel_type]
|
interval = self.coordinator.data[self.entity_description.key][self.channel_type]
|
||||||
|
|
||||||
@ -133,7 +132,7 @@ class AmberForecastSensor(AmberSensor):
|
|||||||
return format_cents_to_dollars(interval.per_kwh)
|
return format_cents_to_dollars(interval.per_kwh)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> Mapping[str, Any] | None:
|
def extra_state_attributes(self) -> dict[str, Any] | None:
|
||||||
"""Return additional pieces of information about the price."""
|
"""Return additional pieces of information about the price."""
|
||||||
intervals = self.coordinator.data[self.entity_description.key].get(
|
intervals = self.coordinator.data[self.entity_description.key].get(
|
||||||
self.channel_type
|
self.channel_type
|
||||||
@ -177,7 +176,7 @@ class AmberPriceDescriptorSensor(AmberSensor):
|
|||||||
@property
|
@property
|
||||||
def native_value(self) -> str | None:
|
def native_value(self) -> str | None:
|
||||||
"""Return the current price descriptor."""
|
"""Return the current price descriptor."""
|
||||||
return self.coordinator.data[self.entity_description.key][self.channel_type]
|
return self.coordinator.data[self.entity_description.key][self.channel_type] # type: ignore[no-any-return]
|
||||||
|
|
||||||
|
|
||||||
class AmberGridSensor(CoordinatorEntity[AmberUpdateCoordinator], SensorEntity):
|
class AmberGridSensor(CoordinatorEntity[AmberUpdateCoordinator], SensorEntity):
|
||||||
@ -199,7 +198,7 @@ class AmberGridSensor(CoordinatorEntity[AmberUpdateCoordinator], SensorEntity):
|
|||||||
@property
|
@property
|
||||||
def native_value(self) -> str | None:
|
def native_value(self) -> str | None:
|
||||||
"""Return the value of the sensor."""
|
"""Return the value of the sensor."""
|
||||||
return self.coordinator.data["grid"][self.entity_description.key]
|
return self.coordinator.data["grid"][self.entity_description.key] # type: ignore[no-any-return]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
@ -213,7 +212,7 @@ async def async_setup_entry(
|
|||||||
current: dict[str, CurrentInterval] = coordinator.data["current"]
|
current: dict[str, CurrentInterval] = coordinator.data["current"]
|
||||||
forecasts: dict[str, list[ForecastInterval]] = coordinator.data["forecasts"]
|
forecasts: dict[str, list[ForecastInterval]] = coordinator.data["forecasts"]
|
||||||
|
|
||||||
entities: list = []
|
entities: list[SensorEntity] = []
|
||||||
for channel_type in current:
|
for channel_type in current:
|
||||||
description = SensorEntityDescription(
|
description = SensorEntityDescription(
|
||||||
key="current",
|
key="current",
|
||||||
|
10
mypy.ini
10
mypy.ini
@ -370,6 +370,16 @@ disallow_untyped_defs = true
|
|||||||
warn_return_any = true
|
warn_return_any = true
|
||||||
warn_unreachable = true
|
warn_unreachable = true
|
||||||
|
|
||||||
|
[mypy-homeassistant.components.amberelectric.*]
|
||||||
|
check_untyped_defs = true
|
||||||
|
disallow_incomplete_defs = true
|
||||||
|
disallow_subclassing_any = true
|
||||||
|
disallow_untyped_calls = true
|
||||||
|
disallow_untyped_decorators = true
|
||||||
|
disallow_untyped_defs = true
|
||||||
|
warn_return_any = true
|
||||||
|
warn_unreachable = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.ambient_station.*]
|
[mypy-homeassistant.components.ambient_station.*]
|
||||||
check_untyped_defs = true
|
check_untyped_defs = true
|
||||||
disallow_incomplete_defs = true
|
disallow_incomplete_defs = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user