diff --git a/homeassistant/components/progettihwsw/binary_sensor.py b/homeassistant/components/progettihwsw/binary_sensor.py index 1ad0d919f15..e6ab49e8e5c 100644 --- a/homeassistant/components/progettihwsw/binary_sensor.py +++ b/homeassistant/components/progettihwsw/binary_sensor.py @@ -7,7 +7,10 @@ from ProgettiHWSW.input import Input import async_timeout from homeassistant.components.binary_sensor import BinarySensorEntity -from homeassistant.helpers.update_coordinator import DataUpdateCoordinator +from homeassistant.helpers.update_coordinator import ( + CoordinatorEntity, + DataUpdateCoordinator, +) from . import setup_input from .const import DEFAULT_POLLING_INTERVAL_SEC, DOMAIN @@ -55,20 +58,14 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities(binary_sensors) -class ProgettihwswBinarySensor(BinarySensorEntity): +class ProgettihwswBinarySensor(CoordinatorEntity, BinarySensorEntity): """Represent a binary sensor.""" def __init__(self, hass, coordinator, config_entry, name, sensor: Input): """Set initializing values.""" + super().__init__(coordinator) self._name = name self._sensor = sensor - self._coordinator = coordinator - - async def async_added_to_hass(self): - """When entity is added to hass.""" - self.async_on_remove( - self._coordinator.async_add_listener(self.async_write_ha_state) - ) @property def name(self): @@ -78,18 +75,4 @@ class ProgettihwswBinarySensor(BinarySensorEntity): @property def is_on(self): """Get sensor state.""" - return self._coordinator.data[self._sensor.id] - - @property - def should_poll(self): - """No need to poll. Coordinator notifies entity of updates.""" - return False - - @property - def available(self): - """Return if entity is available.""" - return self._coordinator.last_update_success - - async def async_update(self): - """Update the state of binary sensor.""" - await self._coordinator.async_request_refresh() + return self.coordinator.data[self._sensor.id] diff --git a/homeassistant/components/progettihwsw/switch.py b/homeassistant/components/progettihwsw/switch.py index b6480d15c7b..5dc6005908f 100644 --- a/homeassistant/components/progettihwsw/switch.py +++ b/homeassistant/components/progettihwsw/switch.py @@ -7,7 +7,10 @@ from ProgettiHWSW.relay import Relay import async_timeout from homeassistant.components.switch import SwitchEntity -from homeassistant.helpers.update_coordinator import DataUpdateCoordinator +from homeassistant.helpers.update_coordinator import ( + CoordinatorEntity, + DataUpdateCoordinator, +) from . import setup_switch from .const import DEFAULT_POLLING_INTERVAL_SEC, DOMAIN @@ -54,35 +57,29 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities(switches) -class ProgettihwswSwitch(SwitchEntity): +class ProgettihwswSwitch(CoordinatorEntity, SwitchEntity): """Represent a switch entity.""" def __init__(self, hass, coordinator, config_entry, name, switch: Relay): """Initialize the values.""" + super().__init__(coordinator) self._switch = switch self._name = name - self._coordinator = coordinator - - async def async_added_to_hass(self): - """When entity is added to hass.""" - self.async_on_remove( - self._coordinator.async_add_listener(self.async_write_ha_state) - ) async def async_turn_on(self, **kwargs): """Turn the switch on.""" await self._switch.control(True) - await self._coordinator.async_request_refresh() + await self.coordinator.async_request_refresh() async def async_turn_off(self, **kwargs): """Turn the switch off.""" await self._switch.control(False) - await self._coordinator.async_request_refresh() + await self.coordinator.async_request_refresh() async def async_toggle(self, **kwargs): """Toggle the state of switch.""" await self._switch.toggle() - await self._coordinator.async_request_refresh() + await self.coordinator.async_request_refresh() @property def name(self): @@ -92,18 +89,4 @@ class ProgettihwswSwitch(SwitchEntity): @property def is_on(self): """Get switch state.""" - return self._coordinator.data[self._switch.id] - - @property - def should_poll(self): - """No need to poll. Coordinator notifies entity of updates.""" - return False - - @property - def available(self): - """Return if entity is available.""" - return self._coordinator.last_update_success - - async def async_update(self): - """Update the state of switch.""" - await self._coordinator.async_request_refresh() + return self.coordinator.data[self._switch.id]