diff --git a/homeassistant/components/switcher_kis/button.py b/homeassistant/components/switcher_kis/button.py index 2e559ba9f3b..5564fac830d 100644 --- a/homeassistant/components/switcher_kis/button.py +++ b/homeassistant/components/switcher_kis/button.py @@ -20,15 +20,13 @@ from homeassistant.components.button import ButtonEntity, ButtonEntityDescriptio from homeassistant.const import EntityCategory from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers import device_registry as dr -from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.update_coordinator import CoordinatorEntity from . import SwitcherConfigEntry from .const import SIGNAL_DEVICE_ADD from .coordinator import SwitcherDataUpdateCoordinator +from .entity import SwitcherEntity from .utils import get_breeze_remote_manager @@ -106,13 +104,10 @@ async def async_setup_entry( ) -class SwitcherThermostatButtonEntity( - CoordinatorEntity[SwitcherDataUpdateCoordinator], ButtonEntity -): +class SwitcherThermostatButtonEntity(SwitcherEntity, ButtonEntity): """Representation of a Switcher climate entity.""" entity_description: SwitcherThermostatButtonEntityDescription - _attr_has_entity_name = True def __init__( self, @@ -126,9 +121,6 @@ class SwitcherThermostatButtonEntity( self._remote = remote self._attr_unique_id = f"{coordinator.mac_address}-{description.key}" - self._attr_device_info = DeviceInfo( - connections={(dr.CONNECTION_NETWORK_MAC, coordinator.mac_address)} - ) async def async_press(self) -> None: """Press the button.""" diff --git a/homeassistant/components/switcher_kis/climate.py b/homeassistant/components/switcher_kis/climate.py index 511630251f2..eeff603bc8a 100644 --- a/homeassistant/components/switcher_kis/climate.py +++ b/homeassistant/components/switcher_kis/climate.py @@ -29,15 +29,13 @@ from homeassistant.components.climate import ( from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers import device_registry as dr -from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.update_coordinator import CoordinatorEntity from . import SwitcherConfigEntry from .const import SIGNAL_DEVICE_ADD from .coordinator import SwitcherDataUpdateCoordinator +from .entity import SwitcherEntity from .utils import get_breeze_remote_manager DEVICE_MODE_TO_HA = { @@ -81,12 +79,9 @@ async def async_setup_entry( ) -class SwitcherClimateEntity( - CoordinatorEntity[SwitcherDataUpdateCoordinator], ClimateEntity -): +class SwitcherClimateEntity(SwitcherEntity, ClimateEntity): """Representation of a Switcher climate entity.""" - _attr_has_entity_name = True _attr_name = None _enable_turn_on_off_backwards_compatibility = False @@ -98,9 +93,6 @@ class SwitcherClimateEntity( self._remote = remote self._attr_unique_id = f"{coordinator.device_id}-{coordinator.mac_address}" - self._attr_device_info = DeviceInfo( - connections={(dr.CONNECTION_NETWORK_MAC, coordinator.mac_address)} - ) self._attr_min_temp = remote.min_temperature self._attr_max_temp = remote.max_temperature diff --git a/homeassistant/components/switcher_kis/cover.py b/homeassistant/components/switcher_kis/cover.py index 5d8a777afa2..d81611b1629 100644 --- a/homeassistant/components/switcher_kis/cover.py +++ b/homeassistant/components/switcher_kis/cover.py @@ -17,14 +17,12 @@ from homeassistant.components.cover import ( from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers import device_registry as dr -from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import SIGNAL_DEVICE_ADD from .coordinator import SwitcherDataUpdateCoordinator +from .entity import SwitcherEntity _LOGGER = logging.getLogger(__name__) @@ -53,12 +51,9 @@ async def async_setup_entry( ) -class SwitcherCoverEntity( - CoordinatorEntity[SwitcherDataUpdateCoordinator], CoverEntity -): +class SwitcherCoverEntity(SwitcherEntity, CoverEntity): """Representation of a Switcher cover entity.""" - _attr_has_entity_name = True _attr_name = None _attr_device_class = CoverDeviceClass.SHUTTER _attr_supported_features = ( @@ -78,9 +73,6 @@ class SwitcherCoverEntity( self._cover_id = cover_id self._attr_unique_id = f"{coordinator.device_id}-{coordinator.mac_address}" - self._attr_device_info = DeviceInfo( - connections={(dr.CONNECTION_NETWORK_MAC, coordinator.mac_address)} - ) self._update_data() diff --git a/homeassistant/components/switcher_kis/entity.py b/homeassistant/components/switcher_kis/entity.py new file mode 100644 index 00000000000..12bde521377 --- /dev/null +++ b/homeassistant/components/switcher_kis/entity.py @@ -0,0 +1,20 @@ +"""Base class for Switcher entities.""" + +from homeassistant.helpers import device_registry as dr +from homeassistant.helpers.device_registry import DeviceInfo +from homeassistant.helpers.update_coordinator import CoordinatorEntity + +from .coordinator import SwitcherDataUpdateCoordinator + + +class SwitcherEntity(CoordinatorEntity[SwitcherDataUpdateCoordinator]): + """Base class for Switcher entities.""" + + _attr_has_entity_name = True + + def __init__(self, coordinator: SwitcherDataUpdateCoordinator) -> None: + """Initialize the entity.""" + super().__init__(coordinator) + self._attr_device_info = DeviceInfo( + connections={(dr.CONNECTION_NETWORK_MAC, coordinator.mac_address)} + ) diff --git a/homeassistant/components/switcher_kis/sensor.py b/homeassistant/components/switcher_kis/sensor.py index ee503dcda95..9ff3d6dfaae 100644 --- a/homeassistant/components/switcher_kis/sensor.py +++ b/homeassistant/components/switcher_kis/sensor.py @@ -13,15 +13,13 @@ from homeassistant.components.sensor import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import UnitOfElectricCurrent, UnitOfPower from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers import device_registry as dr -from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import StateType -from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import SIGNAL_DEVICE_ADD from .coordinator import SwitcherDataUpdateCoordinator +from .entity import SwitcherEntity POWER_SENSORS: list[SensorEntityDescription] = [ SensorEntityDescription( @@ -79,13 +77,9 @@ async def async_setup_entry( ) -class SwitcherSensorEntity( - CoordinatorEntity[SwitcherDataUpdateCoordinator], SensorEntity -): +class SwitcherSensorEntity(SwitcherEntity, SensorEntity): """Representation of a Switcher sensor entity.""" - _attr_has_entity_name = True - def __init__( self, coordinator: SwitcherDataUpdateCoordinator, @@ -98,9 +92,6 @@ class SwitcherSensorEntity( self._attr_unique_id = ( f"{coordinator.device_id}-{coordinator.mac_address}-{description.key}" ) - self._attr_device_info = DeviceInfo( - connections={(dr.CONNECTION_NETWORK_MAC, coordinator.mac_address)} - ) @property def native_value(self) -> StateType: diff --git a/homeassistant/components/switcher_kis/switch.py b/homeassistant/components/switcher_kis/switch.py index c667a6dd473..6a679680263 100644 --- a/homeassistant/components/switcher_kis/switch.py +++ b/homeassistant/components/switcher_kis/switch.py @@ -13,16 +13,10 @@ import voluptuous as vol from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers import ( - config_validation as cv, - device_registry as dr, - entity_platform, -) -from homeassistant.helpers.device_registry import DeviceInfo +from homeassistant.helpers import config_validation as cv, entity_platform from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import VolDictType -from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import ( CONF_AUTO_OFF, @@ -32,6 +26,7 @@ from .const import ( SIGNAL_DEVICE_ADD, ) from .coordinator import SwitcherDataUpdateCoordinator +from .entity import SwitcherEntity _LOGGER = logging.getLogger(__name__) @@ -82,12 +77,9 @@ async def async_setup_entry( ) -class SwitcherBaseSwitchEntity( - CoordinatorEntity[SwitcherDataUpdateCoordinator], SwitchEntity -): +class SwitcherBaseSwitchEntity(SwitcherEntity, SwitchEntity): """Representation of a Switcher switch entity.""" - _attr_has_entity_name = True _attr_name = None def __init__(self, coordinator: SwitcherDataUpdateCoordinator) -> None: @@ -97,9 +89,6 @@ class SwitcherBaseSwitchEntity( # Entity class attributes self._attr_unique_id = f"{coordinator.device_id}-{coordinator.mac_address}" - self._attr_device_info = DeviceInfo( - connections={(dr.CONNECTION_NETWORK_MAC, coordinator.mac_address)} - ) @callback def _handle_coordinator_update(self) -> None: