Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove vera from mypy ignore list #64474

Merged
merged 3 commits into from Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions homeassistant/components/vera/__init__.py
Expand Up @@ -3,6 +3,7 @@

import asyncio
from collections import defaultdict
from collections.abc import Awaitable
import logging
from typing import Any, Generic, TypeVar

Expand Down Expand Up @@ -166,7 +167,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
"""Unload Withings config entry."""
controller_data: ControllerData = get_controller_data(hass, config_entry)

tasks = [
tasks: list[Awaitable] = [
hass.config_entries.async_forward_entry_unload(config_entry, platform)
for platform in get_configured_platforms(controller_data)
]
Expand All @@ -181,7 +182,9 @@ async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry):
await hass.config_entries.async_reload(entry.entry_id)


def map_vera_device(vera_device: veraApi.VeraDevice, remap: list[int]) -> Platform:
def map_vera_device(
vera_device: veraApi.VeraDevice, remap: list[int]
) -> Platform | None:
"""Map vera classes to Home Assistant types."""

type_map = {
Expand Down
9 changes: 3 additions & 6 deletions homeassistant/components/vera/binary_sensor.py
Expand Up @@ -3,12 +3,9 @@

import pyvera as veraApi

from homeassistant.components.binary_sensor import (
DOMAIN as PLATFORM_DOMAIN,
ENTITY_ID_FORMAT,
BinarySensorEntity,
)
from homeassistant.components.binary_sensor import ENTITY_ID_FORMAT, BinarySensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

Expand All @@ -26,7 +23,7 @@ async def async_setup_entry(
async_add_entities(
[
VeraBinarySensor(device, controller_data)
for device in controller_data.devices.get(PLATFORM_DOMAIN)
for device in controller_data.devices[Platform.BINARY_SENSOR]
],
True,
)
Expand Down
17 changes: 9 additions & 8 deletions homeassistant/components/vera/climate.py
Expand Up @@ -5,11 +5,7 @@

import pyvera as veraApi

from homeassistant.components.climate import (
DOMAIN as PLATFORM_DOMAIN,
ENTITY_ID_FORMAT,
ClimateEntity,
)
from homeassistant.components.climate import ENTITY_ID_FORMAT, ClimateEntity
from homeassistant.components.climate.const import (
FAN_AUTO,
FAN_ON,
Expand All @@ -21,7 +17,12 @@
SUPPORT_TARGET_TEMPERATURE,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.const import (
ATTR_TEMPERATURE,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util import convert
Expand All @@ -45,7 +46,7 @@ async def async_setup_entry(
async_add_entities(
[
VeraThermostat(device, controller_data)
for device in controller_data.devices.get(PLATFORM_DOMAIN)
for device in controller_data.devices[Platform.CLIMATE]
],
True,
)
Expand All @@ -62,7 +63,7 @@ def __init__(
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)

@property
def supported_features(self) -> int | None:
def supported_features(self) -> int:
"""Return the list of supported features."""
return SUPPORT_FLAGS

Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/vera/common.py
Expand Up @@ -2,7 +2,6 @@
from __future__ import annotations

from collections import defaultdict
from collections.abc import Sequence
from typing import NamedTuple

import pyvera as pv
Expand All @@ -26,7 +25,7 @@ class ControllerData(NamedTuple):

def get_configured_platforms(controller_data: ControllerData) -> set[Platform]:
"""Get configured platforms for a controller."""
platforms: Sequence[Platform] = []
platforms: list[Platform] = []
for platform in controller_data.devices:
platforms.append(platform)

Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/vera/config_flow.py
@@ -1,6 +1,7 @@
"""Config flow for Vera."""
from __future__ import annotations

from collections.abc import Mapping
import logging
import re
from typing import Any
Expand Down Expand Up @@ -41,7 +42,7 @@ def new_options(lights: list[int], exclude: list[int]) -> dict:
return {CONF_LIGHTS: lights, CONF_EXCLUDE: exclude}


def options_schema(options: dict = None) -> dict:
def options_schema(options: Mapping[str, Any] = None) -> dict:
"""Return options schema."""
options = options or {}
return {
Expand Down
10 changes: 3 additions & 7 deletions homeassistant/components/vera/cover.py
Expand Up @@ -5,13 +5,9 @@

import pyvera as veraApi

from homeassistant.components.cover import (
ATTR_POSITION,
DOMAIN as PLATFORM_DOMAIN,
ENTITY_ID_FORMAT,
CoverEntity,
)
from homeassistant.components.cover import ATTR_POSITION, ENTITY_ID_FORMAT, CoverEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

Expand All @@ -29,7 +25,7 @@ async def async_setup_entry(
async_add_entities(
[
VeraCover(device, controller_data)
for device in controller_data.devices.get(PLATFORM_DOMAIN)
for device in controller_data.devices[Platform.COVER]
],
True,
)
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/vera/light.py
Expand Up @@ -8,13 +8,13 @@
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_HS_COLOR,
DOMAIN as PLATFORM_DOMAIN,
ENTITY_ID_FORMAT,
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR,
LightEntity,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
import homeassistant.util.color as color_util
Expand All @@ -33,7 +33,7 @@ async def async_setup_entry(
async_add_entities(
[
VeraLight(device, controller_data)
for device in controller_data.devices.get(PLATFORM_DOMAIN)
for device in controller_data.devices[Platform.LIGHT]
],
True,
)
Expand All @@ -47,7 +47,7 @@ def __init__(
) -> None:
"""Initialize the light."""
self._state = False
self._color = None
self._color: tuple[float, float] | None = None
self._brightness = None
VeraDevice.__init__(self, vera_device, controller_data)
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
Expand Down
14 changes: 5 additions & 9 deletions homeassistant/components/vera/lock.py
Expand Up @@ -5,13 +5,9 @@

import pyvera as veraApi

from homeassistant.components.lock import (
DOMAIN as PLATFORM_DOMAIN,
ENTITY_ID_FORMAT,
LockEntity,
)
from homeassistant.components.lock import ENTITY_ID_FORMAT, LockEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import STATE_LOCKED, STATE_UNLOCKED
from homeassistant.const import STATE_LOCKED, STATE_UNLOCKED, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

Expand All @@ -32,7 +28,7 @@ async def async_setup_entry(
async_add_entities(
[
VeraLock(device, controller_data)
for device in controller_data.devices.get(PLATFORM_DOMAIN)
for device in controller_data.devices[Platform.LOCK]
],
True,
)
Expand All @@ -45,7 +41,7 @@ def __init__(
self, vera_device: veraApi.VeraLock, controller_data: ControllerData
) -> None:
"""Initialize the Vera device."""
self._state = None
self._state: str | None = None
VeraDevice.__init__(self, vera_device, controller_data)
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)

Expand All @@ -72,7 +68,7 @@ def extra_state_attributes(self) -> dict[str, Any] | None:
changed_by_name is a string like 'Bob'.
low_battery is 1 if an alert fired, 0 otherwise.
"""
data = super().extra_state_attributes
data = super().extra_state_attributes or {}

last_user = self.vera_device.get_last_user_alert()
if last_user is not None:
Expand Down
28 changes: 15 additions & 13 deletions homeassistant/components/vera/sensor.py
Expand Up @@ -6,16 +6,18 @@

import pyvera as veraApi

from homeassistant.components.sensor import (
DOMAIN as PLATFORM_DOMAIN,
ENTITY_ID_FORMAT,
SensorEntity,
)
from homeassistant.components.sensor import ENTITY_ID_FORMAT, SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import LIGHT_LUX, PERCENTAGE, TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.const import (
LIGHT_LUX,
PERCENTAGE,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util import convert
from homeassistant.helpers.typing import StateType

from . import VeraDevice
from .common import ControllerData, get_controller_data
Expand All @@ -33,7 +35,7 @@ async def async_setup_entry(
async_add_entities(
[
VeraSensor(device, controller_data)
for device in controller_data.devices.get(PLATFORM_DOMAIN)
for device in controller_data.devices[Platform.SENSOR]
],
True,
)
Expand All @@ -46,14 +48,14 @@ def __init__(
self, vera_device: veraApi.VeraSensor, controller_data: ControllerData
) -> None:
"""Initialize the sensor."""
self.current_value = None
self._temperature_units = None
self.current_value: StateType = None
self._temperature_units: str | None = None
self.last_changed_time = None
VeraDevice.__init__(self, vera_device, controller_data)
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)

@property
def native_value(self) -> str:
def native_value(self) -> StateType:
"""Return the name of the sensor."""
return self.current_value

Expand All @@ -71,6 +73,7 @@ def native_unit_of_measurement(self) -> str | None:
return PERCENTAGE
if self.vera_device.category == veraApi.CATEGORY_POWER_METER:
return "watts"
return None

def update(self) -> None:
"""Update the state."""
Expand Down Expand Up @@ -101,8 +104,7 @@ def update(self) -> None:
self.current_value = value
self.last_changed_time = time
elif self.vera_device.category == veraApi.CATEGORY_POWER_METER:
power = convert(self.vera_device.power, float, 0)
self.current_value = int(round(power, 0))
self.current_value = self.vera_device.power
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a code change, but the underlying library is typed and returns power as an int

elif self.vera_device.is_trippable:
tripped = self.vera_device.is_tripped
self.current_value = "Tripped" if tripped else "Not Tripped"
Expand Down
9 changes: 3 additions & 6 deletions homeassistant/components/vera/switch.py
Expand Up @@ -5,12 +5,9 @@

import pyvera as veraApi

from homeassistant.components.switch import (
DOMAIN as PLATFORM_DOMAIN,
ENTITY_ID_FORMAT,
SwitchEntity,
)
from homeassistant.components.switch import ENTITY_ID_FORMAT, SwitchEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util import convert
Expand All @@ -29,7 +26,7 @@ async def async_setup_entry(
async_add_entities(
[
VeraSwitch(device, controller_data)
for device in controller_data.devices.get(PLATFORM_DOMAIN)
for device in controller_data.devices[Platform.SWITCH]
],
True,
)
Expand Down
3 changes: 0 additions & 3 deletions mypy.ini
Expand Up @@ -2236,9 +2236,6 @@ ignore_errors = true
[mypy-homeassistant.components.upnp.*]
ignore_errors = true

[mypy-homeassistant.components.vera.*]
ignore_errors = true

[mypy-homeassistant.components.vizio.*]
ignore_errors = true

Expand Down
1 change: 0 additions & 1 deletion script/hassfest/mypy_config.py
Expand Up @@ -87,7 +87,6 @@
"homeassistant.components.toon.*",
"homeassistant.components.unifi.*",
"homeassistant.components.upnp.*",
"homeassistant.components.vera.*",
"homeassistant.components.vizio.*",
"homeassistant.components.withings.*",
"homeassistant.components.xbox.*",
Expand Down