Enable strict typing for amberelectric (#106817)

This commit is contained in:
Marc Mueller 2024-01-01 20:35:34 +01:00 committed by GitHub
parent c5c132e1d4
commit 3b0d877b5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 19 deletions

View file

@ -2,7 +2,6 @@
from __future__ import annotations
from collections.abc import Mapping
from typing import Any
from homeassistant.components.binary_sensor import (
@ -45,14 +44,14 @@ class AmberPriceGridSensor(
@property
def is_on(self) -> bool | None:
"""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):
"""Sensor to show single grid binary values."""
@property
def icon(self):
def icon(self) -> str:
"""Return the sensor icon."""
status = self.coordinator.data["grid"]["price_spike"]
return PRICE_SPIKE_ICONS[status]
@ -60,10 +59,10 @@ class AmberPriceSpikeBinarySensor(AmberPriceGridSensor):
@property
def is_on(self) -> bool | None:
"""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
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."""
spike_status = self.coordinator.data["grid"]["price_spike"]
@ -80,10 +79,10 @@ async def async_setup_entry(
"""Set up a config entry."""
coordinator: AmberUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
entities: list = []
price_spike_description = BinarySensorEntityDescription(
key="price_spike",
name=f"{entry.title} - Price Spike",
)
entities.append(AmberPriceSpikeBinarySensor(coordinator, price_spike_description))
async_add_entities(entities)
async_add_entities(
[AmberPriceSpikeBinarySensor(coordinator, price_spike_description)]
)