From 4c83ecd7bd83ffe5d2a22843d24df1c8a708443e Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Fri, 21 Jan 2022 13:17:45 +0100 Subject: [PATCH] Fix incorrect usage of ToggleEntity in switch platforms (#64620) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Joakim Sørensen --- homeassistant/components/advantage_air/switch.py | 4 ++-- homeassistant/components/bbb_gpio/switch.py | 5 ++--- homeassistant/components/daikin/switch.py | 5 ++--- homeassistant/components/deluge/switch.py | 5 ++--- homeassistant/components/enocean/switch.py | 5 ++--- homeassistant/components/gc100/switch.py | 5 ++--- homeassistant/components/hlk_sw16/switch.py | 4 ++-- homeassistant/components/konnected/switch.py | 5 +++-- homeassistant/components/mcp23017/switch.py | 5 ++--- homeassistant/components/neato/switch.py | 5 +++-- homeassistant/components/nissan_leaf/switch.py | 4 ++-- homeassistant/components/numato/switch.py | 4 ++-- homeassistant/components/raspihats/switch.py | 5 ++--- homeassistant/components/rpi_gpio/switch.py | 5 ++--- homeassistant/components/rpi_pfio/switch.py | 5 ++--- homeassistant/components/synology_dsm/switch.py | 4 ++-- homeassistant/components/tellduslive/switch.py | 4 ++-- homeassistant/components/tellstick/switch.py | 4 ++-- homeassistant/components/transmission/switch.py | 4 ++-- homeassistant/components/volvooncall/switch.py | 4 ++-- homeassistant/components/xs1/switch.py | 4 ++-- 21 files changed, 44 insertions(+), 51 deletions(-) diff --git a/homeassistant/components/advantage_air/switch.py b/homeassistant/components/advantage_air/switch.py index 90c30082329..44be859aa63 100644 --- a/homeassistant/components/advantage_air/switch.py +++ b/homeassistant/components/advantage_air/switch.py @@ -1,7 +1,7 @@ """Switch platform for Advantage Air integration.""" +from homeassistant.components.switch import SwitchEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import ( @@ -28,7 +28,7 @@ async def async_setup_entry( async_add_entities(entities) -class AdvantageAirFreshAir(AdvantageAirEntity, ToggleEntity): +class AdvantageAirFreshAir(AdvantageAirEntity, SwitchEntity): """Representation of Advantage Air fresh air control.""" _attr_icon = "mdi:air-filter" diff --git a/homeassistant/components/bbb_gpio/switch.py b/homeassistant/components/bbb_gpio/switch.py index 8a28fa68798..fc830d2a1a8 100644 --- a/homeassistant/components/bbb_gpio/switch.py +++ b/homeassistant/components/bbb_gpio/switch.py @@ -4,11 +4,10 @@ from __future__ import annotations import voluptuous as vol from homeassistant.components import bbb_gpio -from homeassistant.components.switch import PLATFORM_SCHEMA +from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity from homeassistant.const import CONF_NAME, DEVICE_DEFAULT_NAME from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -44,7 +43,7 @@ def setup_platform( add_entities(switches) -class BBBGPIOSwitch(ToggleEntity): +class BBBGPIOSwitch(SwitchEntity): """Representation of a BeagleBone Black GPIO.""" _attr_should_poll = False diff --git a/homeassistant/components/daikin/switch.py b/homeassistant/components/daikin/switch.py index bf7d4e1ef49..d5601a38989 100644 --- a/homeassistant/components/daikin/switch.py +++ b/homeassistant/components/daikin/switch.py @@ -4,7 +4,6 @@ from __future__ import annotations from homeassistant.components.switch import SwitchEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -34,7 +33,7 @@ async def async_setup_entry( ) -> None: """Set up Daikin climate based on config_entry.""" daikin_api = hass.data[DAIKIN_DOMAIN][entry.entry_id] - switches: list[ToggleEntity] = [] + switches: list[DaikinZoneSwitch | DaikinStreamerSwitch] = [] if zones := daikin_api.device.zones: switches.extend( [ @@ -52,7 +51,7 @@ async def async_setup_entry( async_add_entities(switches) -class DaikinZoneSwitch(ToggleEntity): +class DaikinZoneSwitch(SwitchEntity): """Representation of a zone.""" def __init__(self, daikin_api, zone_id): diff --git a/homeassistant/components/deluge/switch.py b/homeassistant/components/deluge/switch.py index 0372aa56f07..16a5f023052 100644 --- a/homeassistant/components/deluge/switch.py +++ b/homeassistant/components/deluge/switch.py @@ -6,7 +6,7 @@ import logging from deluge_client import DelugeRPCClient, FailedToReconnectException import voluptuous as vol -from homeassistant.components.switch import PLATFORM_SCHEMA +from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity from homeassistant.const import ( CONF_HOST, CONF_NAME, @@ -19,7 +19,6 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant from homeassistant.exceptions import PlatformNotReady import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -63,7 +62,7 @@ def setup_platform( add_entities([DelugeSwitch(deluge_api, name)]) -class DelugeSwitch(ToggleEntity): +class DelugeSwitch(SwitchEntity): """Representation of a Deluge switch.""" def __init__(self, deluge_client, name): diff --git a/homeassistant/components/enocean/switch.py b/homeassistant/components/enocean/switch.py index 78517e07e34..b86b6844551 100644 --- a/homeassistant/components/enocean/switch.py +++ b/homeassistant/components/enocean/switch.py @@ -3,11 +3,10 @@ from __future__ import annotations import voluptuous as vol -from homeassistant.components.switch import PLATFORM_SCHEMA +from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity from homeassistant.const import CONF_ID, CONF_NAME from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -39,7 +38,7 @@ def setup_platform( add_entities([EnOceanSwitch(dev_id, dev_name, channel)]) -class EnOceanSwitch(EnOceanEntity, ToggleEntity): +class EnOceanSwitch(EnOceanEntity, SwitchEntity): """Representation of an EnOcean switch device.""" def __init__(self, dev_id, dev_name, channel): diff --git a/homeassistant/components/gc100/switch.py b/homeassistant/components/gc100/switch.py index bf5bb9c5262..3372203231f 100644 --- a/homeassistant/components/gc100/switch.py +++ b/homeassistant/components/gc100/switch.py @@ -3,11 +3,10 @@ from __future__ import annotations import voluptuous as vol -from homeassistant.components.switch import PLATFORM_SCHEMA +from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity from homeassistant.const import DEVICE_DEFAULT_NAME from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -35,7 +34,7 @@ def setup_platform( add_entities(switches, True) -class GC100Switch(ToggleEntity): +class GC100Switch(SwitchEntity): """Represent a switch/relay from GC100.""" def __init__(self, name, port_addr, gc100): diff --git a/homeassistant/components/hlk_sw16/switch.py b/homeassistant/components/hlk_sw16/switch.py index 701130be4c5..44377093560 100644 --- a/homeassistant/components/hlk_sw16/switch.py +++ b/homeassistant/components/hlk_sw16/switch.py @@ -1,5 +1,5 @@ """Support for HLK-SW16 switches.""" -from homeassistant.components.switch import ToggleEntity +from homeassistant.components.switch import SwitchEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -28,7 +28,7 @@ async def async_setup_entry( async_add_entities(devices_from_entities(hass, entry)) -class SW16Switch(SW16Device, ToggleEntity): +class SW16Switch(SW16Device, SwitchEntity): """Representation of a HLK-SW16 switch.""" @property diff --git a/homeassistant/components/konnected/switch.py b/homeassistant/components/konnected/switch.py index 3702fa725c4..123c5b94ab4 100644 --- a/homeassistant/components/konnected/switch.py +++ b/homeassistant/components/konnected/switch.py @@ -1,6 +1,7 @@ """Support for wired switches attached to a Konnected device.""" import logging +from homeassistant.components.switch import SwitchEntity from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ATTR_STATE, @@ -12,7 +13,7 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect -from homeassistant.helpers.entity import DeviceInfo, ToggleEntity +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import ( @@ -42,7 +43,7 @@ async def async_setup_entry( async_add_entities(switches) -class KonnectedSwitch(ToggleEntity): +class KonnectedSwitch(SwitchEntity): """Representation of a Konnected switch.""" def __init__(self, device_id, zone_num, data): diff --git a/homeassistant/components/mcp23017/switch.py b/homeassistant/components/mcp23017/switch.py index f9211538f56..b67f20e3bf6 100644 --- a/homeassistant/components/mcp23017/switch.py +++ b/homeassistant/components/mcp23017/switch.py @@ -9,11 +9,10 @@ import busio import digitalio import voluptuous as vol -from homeassistant.components.switch import PLATFORM_SCHEMA +from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity from homeassistant.const import DEVICE_DEFAULT_NAME from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -65,7 +64,7 @@ def setup_platform( add_entities(switches) -class MCP23017Switch(ToggleEntity): +class MCP23017Switch(SwitchEntity): """Representation of a MCP23017 output pin.""" def __init__(self, name, pin, invert_logic): diff --git a/homeassistant/components/neato/switch.py b/homeassistant/components/neato/switch.py index 6af87a71fbe..8817e280f43 100644 --- a/homeassistant/components/neato/switch.py +++ b/homeassistant/components/neato/switch.py @@ -8,10 +8,11 @@ from typing import Any from pybotvac.exceptions import NeatoRobotException from pybotvac.robot import Robot +from homeassistant.components.switch import SwitchEntity from homeassistant.config_entries import ConfigEntry from homeassistant.const import STATE_OFF, STATE_ON from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity import DeviceInfo, EntityCategory, ToggleEntity +from homeassistant.helpers.entity import DeviceInfo, EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import NEATO_DOMAIN, NEATO_LOGIN, NEATO_ROBOTS, SCAN_INTERVAL_MINUTES @@ -44,7 +45,7 @@ async def async_setup_entry( async_add_entities(dev, True) -class NeatoConnectedSwitch(ToggleEntity): +class NeatoConnectedSwitch(SwitchEntity): """Neato Connected Switches.""" def __init__(self, neato: NeatoHub, robot: Robot, switch_type: str) -> None: diff --git a/homeassistant/components/nissan_leaf/switch.py b/homeassistant/components/nissan_leaf/switch.py index 3452d6bdecc..0d655622517 100644 --- a/homeassistant/components/nissan_leaf/switch.py +++ b/homeassistant/components/nissan_leaf/switch.py @@ -6,8 +6,8 @@ from typing import Any from pycarwings2.pycarwings2 import Leaf +from homeassistant.components.switch import SwitchEntity from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -35,7 +35,7 @@ def setup_platform( add_entities(entities, True) -class LeafClimateSwitch(LeafEntity, ToggleEntity): +class LeafClimateSwitch(LeafEntity, SwitchEntity): """Nissan Leaf Climate Control switch.""" def __init__(self, car: Leaf) -> None: diff --git a/homeassistant/components/numato/switch.py b/homeassistant/components/numato/switch.py index ed77d8b82cb..312ad4c02a5 100644 --- a/homeassistant/components/numato/switch.py +++ b/homeassistant/components/numato/switch.py @@ -5,6 +5,7 @@ import logging from numato_gpio import NumatoGpioError +from homeassistant.components.switch import SwitchEntity from homeassistant.const import ( CONF_DEVICES, CONF_ID, @@ -12,7 +13,6 @@ from homeassistant.const import ( DEVICE_DEFAULT_NAME, ) from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -64,7 +64,7 @@ def setup_platform( add_entities(switches, True) -class NumatoGpioSwitch(ToggleEntity): +class NumatoGpioSwitch(SwitchEntity): """Representation of a Numato USB GPIO switch port.""" def __init__(self, name, device_id, port, invert_logic, api): diff --git a/homeassistant/components/raspihats/switch.py b/homeassistant/components/raspihats/switch.py index 89ad641544e..0e05e376ed4 100644 --- a/homeassistant/components/raspihats/switch.py +++ b/homeassistant/components/raspihats/switch.py @@ -6,11 +6,10 @@ from typing import TYPE_CHECKING import voluptuous as vol -from homeassistant.components.switch import PLATFORM_SCHEMA +from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity from homeassistant.const import CONF_ADDRESS, CONF_NAME, DEVICE_DEFAULT_NAME from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -90,7 +89,7 @@ def setup_platform( add_entities(switches) -class I2CHatSwitch(ToggleEntity): +class I2CHatSwitch(SwitchEntity): """Representation a switch that uses a I2C-HAT digital output.""" I2C_HATS_MANAGER: I2CHatsManager | None = None diff --git a/homeassistant/components/rpi_gpio/switch.py b/homeassistant/components/rpi_gpio/switch.py index 3c323295411..040edd912c5 100644 --- a/homeassistant/components/rpi_gpio/switch.py +++ b/homeassistant/components/rpi_gpio/switch.py @@ -4,11 +4,10 @@ from __future__ import annotations import voluptuous as vol from homeassistant.components import rpi_gpio -from homeassistant.components.switch import PLATFORM_SCHEMA +from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity from homeassistant.const import DEVICE_DEFAULT_NAME from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.reload import setup_reload_service from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -49,7 +48,7 @@ def setup_platform( add_entities(switches) -class RPiGPIOSwitch(ToggleEntity): +class RPiGPIOSwitch(SwitchEntity): """Representation of a Raspberry Pi GPIO.""" def __init__(self, name, port, invert_logic): diff --git a/homeassistant/components/rpi_pfio/switch.py b/homeassistant/components/rpi_pfio/switch.py index c5af1bbf2e1..ca3d176eecb 100644 --- a/homeassistant/components/rpi_pfio/switch.py +++ b/homeassistant/components/rpi_pfio/switch.py @@ -4,11 +4,10 @@ from __future__ import annotations import voluptuous as vol from homeassistant.components import rpi_pfio -from homeassistant.components.switch import PLATFORM_SCHEMA +from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity from homeassistant.const import ATTR_NAME, DEVICE_DEFAULT_NAME from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -47,7 +46,7 @@ def setup_platform( add_entities(switches) -class RPiPFIOSwitch(ToggleEntity): +class RPiPFIOSwitch(SwitchEntity): """Representation of a PiFace Digital Output.""" def __init__(self, port, name, invert_logic): diff --git a/homeassistant/components/synology_dsm/switch.py b/homeassistant/components/synology_dsm/switch.py index fb3f50479dd..3b3b801fcf7 100644 --- a/homeassistant/components/synology_dsm/switch.py +++ b/homeassistant/components/synology_dsm/switch.py @@ -6,7 +6,7 @@ from typing import Any from synology_dsm.api.surveillance_station import SynoSurveillanceStation -from homeassistant.components.switch import ToggleEntity +from homeassistant.components.switch import SwitchEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo @@ -54,7 +54,7 @@ async def async_setup_entry( async_add_entities(entities, True) -class SynoDSMSurveillanceHomeModeToggle(SynologyDSMBaseEntity, ToggleEntity): +class SynoDSMSurveillanceHomeModeToggle(SynologyDSMBaseEntity, SwitchEntity): """Representation a Synology Surveillance Station Home Mode toggle.""" coordinator: DataUpdateCoordinator[dict[str, dict[str, bool]]] diff --git a/homeassistant/components/tellduslive/switch.py b/homeassistant/components/tellduslive/switch.py index 209897c32ba..78b31e8fea7 100644 --- a/homeassistant/components/tellduslive/switch.py +++ b/homeassistant/components/tellduslive/switch.py @@ -1,9 +1,9 @@ """Support for Tellstick switches using Tellstick Net.""" from homeassistant.components import switch, tellduslive +from homeassistant.components.switch import SwitchEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.dispatcher import async_dispatcher_connect -from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity_platform import AddEntitiesCallback from .entry import TelldusLiveEntity @@ -28,7 +28,7 @@ async def async_setup_entry( ) -class TelldusLiveSwitch(TelldusLiveEntity, ToggleEntity): +class TelldusLiveSwitch(TelldusLiveEntity, SwitchEntity): """Representation of a Tellstick switch.""" @property diff --git a/homeassistant/components/tellstick/switch.py b/homeassistant/components/tellstick/switch.py index 2931210b961..5f88bab420b 100644 --- a/homeassistant/components/tellstick/switch.py +++ b/homeassistant/components/tellstick/switch.py @@ -1,8 +1,8 @@ """Support for Tellstick switches.""" from __future__ import annotations +from homeassistant.components.switch import SwitchEntity from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -39,7 +39,7 @@ def setup_platform( ) -class TellstickSwitch(TellstickDevice, ToggleEntity): +class TellstickSwitch(TellstickDevice, SwitchEntity): """Representation of a Tellstick switch.""" def _parse_ha_data(self, kwargs): diff --git a/homeassistant/components/transmission/switch.py b/homeassistant/components/transmission/switch.py index 2aaa8076062..a646286e34f 100644 --- a/homeassistant/components/transmission/switch.py +++ b/homeassistant/components/transmission/switch.py @@ -1,11 +1,11 @@ """Support for setting the Transmission BitTorrent client Turtle Mode.""" import logging +from homeassistant.components.switch import SwitchEntity from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_NAME, STATE_OFF, STATE_ON from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect -from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import DOMAIN, SWITCH_TYPES @@ -30,7 +30,7 @@ async def async_setup_entry( async_add_entities(dev, True) -class TransmissionSwitch(ToggleEntity): +class TransmissionSwitch(SwitchEntity): """Representation of a Transmission switch.""" def __init__(self, switch_type, switch_name, tm_client, name): diff --git a/homeassistant/components/volvooncall/switch.py b/homeassistant/components/volvooncall/switch.py index 431dc02d41e..63758ac010b 100644 --- a/homeassistant/components/volvooncall/switch.py +++ b/homeassistant/components/volvooncall/switch.py @@ -1,8 +1,8 @@ """Support for Volvo heater.""" from __future__ import annotations +from homeassistant.components.switch import SwitchEntity from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -21,7 +21,7 @@ async def async_setup_platform( async_add_entities([VolvoSwitch(hass.data[DATA_KEY], *discovery_info)]) -class VolvoSwitch(VolvoEntity, ToggleEntity): +class VolvoSwitch(VolvoEntity, SwitchEntity): """Representation of a Volvo switch.""" @property diff --git a/homeassistant/components/xs1/switch.py b/homeassistant/components/xs1/switch.py index 7547da9ebc5..0f40678986b 100644 --- a/homeassistant/components/xs1/switch.py +++ b/homeassistant/components/xs1/switch.py @@ -3,8 +3,8 @@ from __future__ import annotations from xs1_api_client.api_constants import ActuatorType +from homeassistant.components.switch import SwitchEntity from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -30,7 +30,7 @@ def setup_platform( add_entities(switch_entities) -class XS1SwitchEntity(XS1DeviceEntity, ToggleEntity): +class XS1SwitchEntity(XS1DeviceEntity, SwitchEntity): """Representation of a XS1 switch actuator.""" @property