mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
strictly type: fan.py, light.py, switch.py. (#56379)
This commit is contained in:
parent
cce906f968
commit
1cc850877f
@ -2,11 +2,13 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.fan import FanEntity
|
from homeassistant.components.fan import FanEntity
|
||||||
from homeassistant.const import CONF_NAME
|
from homeassistant.const import CONF_NAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from . import get_hub
|
from . import get_hub
|
||||||
from .base_platform import BaseSwitch
|
from .base_platform import BaseSwitch
|
||||||
@ -18,8 +20,11 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(
|
async def async_setup_platform(
|
||||||
hass: HomeAssistant, config: ConfigType, async_add_entities, discovery_info=None
|
hass: HomeAssistant,
|
||||||
):
|
config: ConfigType,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
|
) -> None:
|
||||||
"""Read configuration and create Modbus fans."""
|
"""Read configuration and create Modbus fans."""
|
||||||
if discovery_info is None: # pragma: no cover
|
if discovery_info is None: # pragma: no cover
|
||||||
return
|
return
|
||||||
@ -39,13 +44,13 @@ class ModbusFan(BaseSwitch, FanEntity):
|
|||||||
speed: str | None = None,
|
speed: str | None = None,
|
||||||
percentage: int | None = None,
|
percentage: int | None = None,
|
||||||
preset_mode: str | None = None,
|
preset_mode: str | None = None,
|
||||||
**kwargs,
|
**kwargs: Any,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set fan on."""
|
"""Set fan on."""
|
||||||
await self.async_turn(self.command_on)
|
await self.async_turn(self.command_on)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self) -> bool:
|
||||||
"""Return true if fan is on.
|
"""Return true if fan is on.
|
||||||
|
|
||||||
This is needed due to the ongoing conversion of fan.
|
This is needed due to the ongoing conversion of fan.
|
||||||
|
@ -2,11 +2,13 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.light import LightEntity
|
from homeassistant.components.light import LightEntity
|
||||||
from homeassistant.const import CONF_LIGHTS, CONF_NAME
|
from homeassistant.const import CONF_LIGHTS, CONF_NAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from . import get_hub
|
from . import get_hub
|
||||||
from .base_platform import BaseSwitch
|
from .base_platform import BaseSwitch
|
||||||
@ -17,8 +19,11 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(
|
async def async_setup_platform(
|
||||||
hass: HomeAssistant, config: ConfigType, async_add_entities, discovery_info=None
|
hass: HomeAssistant,
|
||||||
):
|
config: ConfigType,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
|
) -> None:
|
||||||
"""Read configuration and create Modbus lights."""
|
"""Read configuration and create Modbus lights."""
|
||||||
if discovery_info is None: # pragma: no cover
|
if discovery_info is None: # pragma: no cover
|
||||||
return
|
return
|
||||||
@ -33,6 +38,6 @@ async def async_setup_platform(
|
|||||||
class ModbusLight(BaseSwitch, LightEntity):
|
class ModbusLight(BaseSwitch, LightEntity):
|
||||||
"""Class representing a Modbus light."""
|
"""Class representing a Modbus light."""
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs):
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Set light on."""
|
"""Set light on."""
|
||||||
await self.async_turn(self.command_on)
|
await self.async_turn(self.command_on)
|
||||||
|
@ -2,11 +2,13 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity
|
from homeassistant.components.switch import SwitchEntity
|
||||||
from homeassistant.const import CONF_NAME, CONF_SWITCHES
|
from homeassistant.const import CONF_NAME, CONF_SWITCHES
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from . import get_hub
|
from . import get_hub
|
||||||
from .base_platform import BaseSwitch
|
from .base_platform import BaseSwitch
|
||||||
@ -17,8 +19,11 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(
|
async def async_setup_platform(
|
||||||
hass: HomeAssistant, config: ConfigType, async_add_entities, discovery_info=None
|
hass: HomeAssistant,
|
||||||
):
|
config: ConfigType,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
|
) -> None:
|
||||||
"""Read configuration and create Modbus switches."""
|
"""Read configuration and create Modbus switches."""
|
||||||
switches = []
|
switches = []
|
||||||
|
|
||||||
@ -34,6 +39,6 @@ async def async_setup_platform(
|
|||||||
class ModbusSwitch(BaseSwitch, SwitchEntity):
|
class ModbusSwitch(BaseSwitch, SwitchEntity):
|
||||||
"""Base class representing a Modbus switch."""
|
"""Base class representing a Modbus switch."""
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs):
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Set switch on."""
|
"""Set switch on."""
|
||||||
await self.async_turn(self.command_on)
|
await self.async_turn(self.command_on)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user