Enable strict typing for co2signal (#106888)

This commit is contained in:
Marc Mueller 2024-01-02 20:41:39 +01:00 committed by GitHub
parent dcee8e67c4
commit fde03d7888
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 4 deletions

View File

@ -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.*

View File

@ -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),
)

View File

@ -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)}"

View File

@ -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