Skip to content

Commit

Permalink
Add missing type hints in fans (home-assistant#73835)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Jun 22, 2022
1 parent 532e25d commit 6b6e5fa
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 75 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/comfoconnect/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def turn_on(
self,
percentage: int | None = None,
preset_mode: str | None = None,
**kwargs,
**kwargs: Any,
) -> None:
"""Turn on the fan."""
if percentage is None:
Expand Down
14 changes: 8 additions & 6 deletions homeassistant/components/demo/fan.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Demo fan platform that has a fake fan."""
from __future__ import annotations

from typing import Any

from homeassistant.components.fan import FanEntity, FanEntityFeature
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
Expand Down Expand Up @@ -192,9 +194,9 @@ def set_preset_mode(self, preset_mode: str) -> None:

def turn_on(
self,
percentage: int = None,
preset_mode: str = None,
**kwargs,
percentage: int | None = None,
preset_mode: str | None = None,
**kwargs: Any,
) -> None:
"""Turn on the entity."""
if preset_mode:
Expand Down Expand Up @@ -262,9 +264,9 @@ async def async_set_preset_mode(self, preset_mode: str) -> None:

async def async_turn_on(
self,
percentage: int = None,
preset_mode: str = None,
**kwargs,
percentage: int | None = None,
preset_mode: str | None = None,
**kwargs: Any,
) -> None:
"""Turn on the entity."""
if preset_mode:
Expand Down
8 changes: 5 additions & 3 deletions homeassistant/components/fjaraskupan/fan.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Support for Fjäråskupan fans."""
from __future__ import annotations

from typing import Any

from fjaraskupan import (
COMMAND_AFTERCOOKINGTIMERAUTO,
COMMAND_AFTERCOOKINGTIMERMANUAL,
Expand Down Expand Up @@ -93,9 +95,9 @@ async def async_set_percentage(self, percentage: int) -> None:

async def async_turn_on(
self,
percentage: int = None,
preset_mode: str = None,
**kwargs,
percentage: int | None = None,
preset_mode: str | None = None,
**kwargs: Any,
) -> None:
"""Turn on the fan."""

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/freedompro/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def is_on(self) -> bool | None:
return self._attr_is_on

@property
def percentage(self):
def percentage(self) -> int | None:
"""Return the current speed percentage."""
return self._attr_percentage

Expand Down Expand Up @@ -111,7 +111,7 @@ async def async_turn_off(self, **kwargs):
)
await self.coordinator.async_request_refresh()

async def async_set_percentage(self, percentage: int):
async def async_set_percentage(self, percentage: int) -> None:
"""Set the speed percentage of the fan."""
rotation_speed = {"rotationSpeed": percentage}
payload = json.dumps(rotation_speed)
Expand Down
7 changes: 4 additions & 3 deletions homeassistant/components/insteon/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import math
from typing import Any

from homeassistant.components.fan import (
DOMAIN as FAN_DOMAIN,
Expand Down Expand Up @@ -62,9 +63,9 @@ def speed_count(self) -> int:

async def async_turn_on(
self,
percentage: int = None,
preset_mode: str = None,
**kwargs,
percentage: int | None = None,
preset_mode: str | None = None,
**kwargs: Any,
) -> None:
"""Turn on the fan."""
await self.async_set_percentage(percentage or 67)
Expand Down
10 changes: 6 additions & 4 deletions homeassistant/components/lutron_caseta/fan.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Support for Lutron Caseta fans."""
from __future__ import annotations

from typing import Any

from pylutron_caseta import FAN_HIGH, FAN_LOW, FAN_MEDIUM, FAN_MEDIUM_HIGH, FAN_OFF

from homeassistant.components.fan import DOMAIN, FanEntity, FanEntityFeature
Expand Down Expand Up @@ -58,10 +60,10 @@ def percentage(self) -> int | None:

async def async_turn_on(
self,
percentage: int = None,
preset_mode: str = None,
**kwargs,
):
percentage: int | None = None,
preset_mode: str | None = None,
**kwargs: Any,
) -> None:
"""Turn the fan on."""
if percentage is None:
percentage = DEFAULT_ON_PERCENTAGE
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/modern_forms/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ async def async_set_percentage(self, percentage: int) -> None:
async def async_turn_on(
self,
percentage: int | None = None,
preset_mode: int | None = None,
preset_mode: str | None = None,
**kwargs: Any,
) -> None:
"""Turn on the fan."""
Expand Down
15 changes: 8 additions & 7 deletions homeassistant/components/mqtt/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import functools
import logging
import math
from typing import Any

import voluptuous as vol

Expand Down Expand Up @@ -511,17 +512,17 @@ def is_on(self) -> bool | None:
return self._state

@property
def percentage(self):
def percentage(self) -> int | None:
"""Return the current percentage."""
return self._percentage

@property
def preset_mode(self):
def preset_mode(self) -> str | None:
"""Return the current preset _mode."""
return self._preset_mode

@property
def preset_modes(self) -> list:
def preset_modes(self) -> list[str]:
"""Get the list of available preset modes."""
return self._preset_modes

Expand All @@ -536,16 +537,16 @@ def speed_count(self) -> int:
return self._speed_count

@property
def oscillating(self):
def oscillating(self) -> bool | None:
"""Return the oscillation state."""
return self._oscillation

# The speed attribute deprecated in the schema, support will be removed after a quarter (2021.7)
async def async_turn_on(
self,
percentage: int = None,
preset_mode: str = None,
**kwargs,
percentage: int | None = None,
preset_mode: str | None = None,
**kwargs: Any,
) -> None:
"""Turn on the entity.
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/smartthings/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from collections.abc import Sequence
import math
from typing import Any

from pysmartthings import Capability

Expand Down Expand Up @@ -72,7 +73,7 @@ async def async_turn_on(
self,
percentage: int | None = None,
preset_mode: str | None = None,
**kwargs,
**kwargs: Any,
) -> None:
"""Turn the fan on."""
await self._async_set_percentage(percentage)
Expand Down
10 changes: 8 additions & 2 deletions homeassistant/components/smarty/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import logging
import math
from typing import Any

from homeassistant.components.fan import FanEntity, FanEntityFeature
from homeassistant.core import HomeAssistant, callback
Expand Down Expand Up @@ -64,7 +65,7 @@ def icon(self):
return "mdi:air-conditioner"

@property
def is_on(self):
def is_on(self) -> bool:
"""Return state of the fan."""
return bool(self._smarty_fan_speed)

Expand Down Expand Up @@ -96,7 +97,12 @@ def set_percentage(self, percentage: int) -> None:
self._smarty_fan_speed = fan_speed
self.schedule_update_ha_state()

def turn_on(self, percentage=None, preset_mode=None, **kwargs):
def turn_on(
self,
percentage: int | None = None,
preset_mode: str | None = None,
**kwargs: Any,
) -> None:
"""Turn on the fan."""
_LOGGER.debug("Turning on fan. percentage is %s", percentage)
self.set_percentage(percentage or DEFAULT_ON_PERCENTAGE)
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/switch_as_x/fan.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Fan support for switch entities."""
from __future__ import annotations

from typing import Any

from homeassistant.components.fan import FanEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_ENTITY_ID
Expand Down Expand Up @@ -53,7 +55,7 @@ async def async_turn_on(
self,
percentage: int | None = None,
preset_mode: str | None = None,
**kwargs,
**kwargs: Any,
) -> None:
"""Turn on the fan.
Expand Down
16 changes: 8 additions & 8 deletions homeassistant/components/template/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,35 +215,35 @@ def preset_modes(self) -> list[str]:
return self._preset_modes

@property
def is_on(self):
def is_on(self) -> bool:
"""Return true if device is on."""
return self._state == STATE_ON

@property
def preset_mode(self):
def preset_mode(self) -> str | None:
"""Return the current preset mode."""
return self._preset_mode

@property
def percentage(self):
def percentage(self) -> int | None:
"""Return the current speed percentage."""
return self._percentage

@property
def oscillating(self):
def oscillating(self) -> bool | None:
"""Return the oscillation state."""
return self._oscillating

@property
def current_direction(self):
def current_direction(self) -> str | None:
"""Return the oscillation state."""
return self._direction

async def async_turn_on(
self,
percentage: int = None,
preset_mode: str = None,
**kwargs,
percentage: int | None = None,
preset_mode: str | None = None,
**kwargs: Any,
) -> None:
"""Turn on the fan."""
await self.async_run_script(
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/tuya/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ def turn_off(self, **kwargs: Any) -> None:

def turn_on(
self,
percentage: int = None,
preset_mode: str = None,
percentage: int | None = None,
preset_mode: str | None = None,
**kwargs: Any,
) -> None:
"""Turn on the fan."""
Expand Down
17 changes: 10 additions & 7 deletions homeassistant/components/vesync/fan.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Support for VeSync fans."""
from __future__ import annotations

import logging
import math
from typing import Any

from homeassistant.components.fan import FanEntity, FanEntityFeature
from homeassistant.config_entries import ConfigEntry
Expand Down Expand Up @@ -91,7 +94,7 @@ def __init__(self, fan):
self.smartfan = fan

@property
def percentage(self):
def percentage(self) -> int | None:
"""Return the current speed."""
if (
self.smartfan.mode == "manual"
Expand All @@ -115,7 +118,7 @@ def preset_modes(self):
return PRESET_MODES[SKU_TO_BASE_DEVICE.get(self.device.device_type)]

@property
def preset_mode(self):
def preset_mode(self) -> str | None:
"""Get the current preset mode."""
if self.smartfan.mode in (FAN_MODE_AUTO, FAN_MODE_SLEEP):
return self.smartfan.mode
Expand Down Expand Up @@ -148,7 +151,7 @@ def extra_state_attributes(self):

return attr

def set_percentage(self, percentage):
def set_percentage(self, percentage: int) -> None:
"""Set the speed of the device."""
if percentage == 0:
self.smartfan.turn_off()
Expand All @@ -167,7 +170,7 @@ def set_percentage(self, percentage):
)
self.schedule_update_ha_state()

def set_preset_mode(self, preset_mode):
def set_preset_mode(self, preset_mode: str) -> None:
"""Set the preset mode of device."""
if preset_mode not in self.preset_modes:
raise ValueError(
Expand All @@ -187,9 +190,9 @@ def set_preset_mode(self, preset_mode):

def turn_on(
self,
percentage: int = None,
preset_mode: str = None,
**kwargs,
percentage: int | None = None,
preset_mode: str | None = None,
**kwargs: Any,
) -> None:
"""Turn the device on."""
if preset_mode:
Expand Down
Loading

0 comments on commit 6b6e5fa

Please sign in to comment.