Skip to content

Commit

Permalink
fix: mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
bramstroker committed May 3, 2024
1 parent a048830 commit 86cf02e
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 62 deletions.
12 changes: 3 additions & 9 deletions custom_components/powercalc/const.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
"""The Powercalc constants."""

from datetime import timedelta
from enum import StrEnum
from typing import Literal

from awesomeversion.awesomeversion import AwesomeVersion
from homeassistant.const import __version__ as HA_VERSION # noqa

if AwesomeVersion(HA_VERSION) >= AwesomeVersion("2023.8.0"):
from enum import StrEnum
else:
from homeassistant.backports.enum import StrEnum # pragma: no cover

from homeassistant.components.utility_meter.const import DAILY, MONTHLY, WEEKLY
from homeassistant.const import (
STATE_NOT_HOME,
STATE_OFF,
STATE_STANDBY,
STATE_UNAVAILABLE,
)
from homeassistant.const import __version__ as HA_VERSION # noqa

MIN_HA_VERSION = "2023.1"
MIN_HA_VERSION = "2024.3"

DOMAIN = "powercalc"
DOMAIN_CONFIG = "config"
Expand Down
13 changes: 3 additions & 10 deletions custom_components/powercalc/group_include/filter.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from __future__ import annotations

import re
from enum import StrEnum
from typing import Protocol, cast

from awesomeversion.awesomeversion import AwesomeVersion
from homeassistant.components.group import DOMAIN as GROUP_DOMAIN
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.const import ATTR_ENTITY_ID, CONF_DOMAIN
from homeassistant.const import __version__ as HA_VERSION # noqa
from homeassistant.core import HomeAssistant, split_entity_id
from homeassistant.helpers import area_registry, device_registry, entity_registry
from homeassistant.helpers.area_registry import AreaEntry
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.entity_registry import RegistryEntry
from homeassistant.helpers.template import Template
from homeassistant.helpers.typing import ConfigType

Expand All @@ -27,14 +28,6 @@
)
from custom_components.powercalc.errors import SensorConfigurationError

if AwesomeVersion(HA_VERSION) >= AwesomeVersion("2023.8.0"):
from enum import StrEnum
else:
from homeassistant.backports.enum import StrEnum # pragma: no cover

from homeassistant.const import CONF_DOMAIN
from homeassistant.helpers.entity_registry import RegistryEntry


class FilterOperator(StrEnum):
AND = "and"
Expand Down
13 changes: 3 additions & 10 deletions custom_components/powercalc/power_profile/power_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,15 @@
import logging
import os
import re
from enum import StrEnum
from typing import NamedTuple, Protocol

from awesomeversion.awesomeversion import AwesomeVersion
from homeassistant.const import __version__ as HA_VERSION # noqa

from custom_components.powercalc.helpers import get_library_path

if AwesomeVersion(HA_VERSION) >= AwesomeVersion("2023.8.0"):
from enum import StrEnum
else:
from homeassistant.backports.enum import StrEnum # pragma: no cover

from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
from homeassistant.components.media_player import DOMAIN as MEDIA_PLAYER_DOMAIN
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.const import __version__ as HA_VERSION # noqa
from homeassistant.core import HomeAssistant, State
from homeassistant.helpers.typing import ConfigType

Expand All @@ -31,6 +23,7 @@
PowercalcSetupError,
UnsupportedStrategyError,
)
from custom_components.powercalc.helpers import get_library_path

_LOGGER = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions custom_components/powercalc/sensors/utility_meter.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ async def create_utility_meter(
if "sensor_always_available" in signature.parameters:
params["sensor_always_available"] = sensor_config.get(CONF_IGNORE_UNAVAILABLE_STATE) or False

utility_meter = VirtualUtilityMeter(**params)
utility_meter = VirtualUtilityMeter(**params) # type: ignore[no-untyped-call]
utility_meter.rounding_digits = sensor_config.get(CONF_ENERGY_SENSOR_PRECISION) # type: ignore
utility_meter.entity_id = entity_id

return utility_meter


class VirtualUtilityMeter(UtilityMeterSensor, BaseEntity): # type: ignore
class VirtualUtilityMeter(UtilityMeterSensor, BaseEntity):
rounding_digits: int = DEFAULT_ENERGY_SENSOR_PRECISION

@property
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"render_readme": false,
"zip_release": true,
"filename": "powercalc.zip",
"homeassistant": "2023.1.0"
"homeassistant": "2024.3.0"
}
58 changes: 29 additions & 29 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ readme = "README.md"
[tool.poetry.group.dev.dependencies]
pre-commit = "^3.3"
ruff = "^0.4.0"
mypy = "1.8.0"
mypy = "1.10.0"
voluptuous-stubs = "^0.1"
homeassistant-stubs = "*"
freezegun = "1.4.0"
Expand Down

0 comments on commit 86cf02e

Please sign in to comment.