Enable strict typing for co2signal (#106888)
parent
dcee8e67c4
commit
fde03d7888
|
@ -116,6 +116,7 @@ homeassistant.components.clickatell.*
|
|||
homeassistant.components.clicksend.*
|
||||
homeassistant.components.climate.*
|
||||
homeassistant.components.cloud.*
|
||||
homeassistant.components.co2signal.*
|
||||
homeassistant.components.command_line.*
|
||||
homeassistant.components.configurator.*
|
||||
homeassistant.components.cover.*
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
"""Helper functions for the CO2 Signal integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
from typing import Any
|
||||
|
||||
|
@ -16,11 +18,11 @@ async def fetch_latest_carbon_intensity(
|
|||
) -> CarbonIntensityResponse:
|
||||
"""Fetch the latest carbon intensity based on country code or location coordinates."""
|
||||
if CONF_COUNTRY_CODE in config:
|
||||
return await em.latest_carbon_intensity_by_country_code(
|
||||
return await em.latest_carbon_intensity_by_country_code( # type: ignore[no-any-return]
|
||||
code=config[CONF_COUNTRY_CODE]
|
||||
)
|
||||
|
||||
return await em.latest_carbon_intensity_by_coordinates(
|
||||
return await em.latest_carbon_intensity_by_coordinates( # type: ignore[no-any-return]
|
||||
lat=config.get(CONF_LATITUDE, hass.config.latitude),
|
||||
lon=config.get(CONF_LONGITUDE, hass.config.longitude),
|
||||
)
|
||||
|
|
|
@ -2,14 +2,15 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.const import CONF_COUNTRY_CODE, CONF_LATITUDE, CONF_LONGITUDE
|
||||
|
||||
|
||||
def get_extra_name(config: Mapping) -> str | None:
|
||||
def get_extra_name(config: Mapping[str, Any]) -> str | None:
|
||||
"""Return the extra name describing the location if not home."""
|
||||
if CONF_COUNTRY_CODE in config:
|
||||
return config[CONF_COUNTRY_CODE]
|
||||
return config[CONF_COUNTRY_CODE] # type: ignore[no-any-return]
|
||||
|
||||
if CONF_LATITUDE in config:
|
||||
return f"{round(config[CONF_LATITUDE], 2)}, {round(config[CONF_LONGITUDE], 2)}"
|
||||
|
|
10
mypy.ini
10
mypy.ini
|
@ -920,6 +920,16 @@ disallow_untyped_defs = true
|
|||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.co2signal.*]
|
||||
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.command_line.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
|
|
Loading…
Reference in New Issue