diff --git a/homeassistant/components/somfy_mylink/cover.py b/homeassistant/components/somfy_mylink/cover.py index b4eb847a5e0..480eeda9fd1 100644 --- a/homeassistant/components/somfy_mylink/cover.py +++ b/homeassistant/components/somfy_mylink/cover.py @@ -1,12 +1,7 @@ """Cover Platform for the Somfy MyLink component.""" import logging -from homeassistant.components.cover import ( - DEVICE_CLASS_BLIND, - DEVICE_CLASS_SHUTTER, - DEVICE_CLASS_WINDOW, - CoverEntity, -) +from homeassistant.components.cover import CoverDeviceClass, CoverEntity from homeassistant.const import STATE_CLOSED, STATE_OPEN from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.restore_state import RestoreEntity @@ -21,7 +16,10 @@ from .const import ( _LOGGER = logging.getLogger(__name__) -MYLINK_COVER_TYPE_TO_DEVICE_CLASS = {0: DEVICE_CLASS_BLIND, 1: DEVICE_CLASS_SHUTTER} +MYLINK_COVER_TYPE_TO_DEVICE_CLASS = { + 0: CoverDeviceClass.BLIND, + 1: CoverDeviceClass.SHUTTER, +} async def async_setup_entry(hass, config_entry, async_add_entities): @@ -38,7 +36,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): "target_id": cover["targetID"], "name": cover["name"], "device_class": MYLINK_COVER_TYPE_TO_DEVICE_CLASS.get( - cover.get("type"), DEVICE_CLASS_WINDOW + cover.get("type"), CoverDeviceClass.WINDOW ), "reverse": reversed_target_ids.get(cover["targetID"], False), } @@ -57,76 +55,33 @@ async def async_setup_entry(hass, config_entry, async_add_entities): class SomfyShade(RestoreEntity, CoverEntity): """Object for controlling a Somfy cover.""" + _attr_should_poll = False + _attr_assumed_state = True + def __init__( self, somfy_mylink, target_id, name="SomfyShade", reverse=False, - device_class=DEVICE_CLASS_WINDOW, + device_class=CoverDeviceClass.WINDOW, ): """Initialize the cover.""" self.somfy_mylink = somfy_mylink self._target_id = target_id - self._name = name + self._attr_unique_id = target_id + self._attr_name = name self._reverse = reverse - self._closed = None - self._is_opening = None - self._is_closing = None - self._device_class = device_class - - @property - def should_poll(self): - """No polling since assumed state.""" - return False - - @property - def unique_id(self): - """Return the unique ID of this cover.""" - return self._target_id - - @property - def name(self): - """Return the name of the cover.""" - return self._name - - @property - def assumed_state(self): - """Let HA know the integration is assumed state.""" - return True - - @property - def device_class(self): - """Return the class of this device, from component DEVICE_CLASSES.""" - return self._device_class - - @property - def is_opening(self): - """Return if the cover is opening.""" - return self._is_opening - - @property - def is_closing(self): - """Return if the cover is closing.""" - return self._is_closing - - @property - def is_closed(self) -> bool: - """Return if the cover is closed.""" - return self._closed - - @property - def device_info(self) -> DeviceInfo: - """Return the device_info of the device.""" - return DeviceInfo( + self._attr_device_class = device_class + self._attr_device_info = DeviceInfo( identifiers={(DOMAIN, self._target_id)}, manufacturer=MANUFACTURER, - name=self._name, + name=name, ) async def async_close_cover(self, **kwargs): """Close the cover.""" - self._is_closing = True + self._attr_is_closing = True self.async_write_ha_state() try: # Blocks until the close command is sent @@ -134,14 +89,14 @@ class SomfyShade(RestoreEntity, CoverEntity): await self.somfy_mylink.move_down(self._target_id) else: await self.somfy_mylink.move_up(self._target_id) - self._closed = True + self._attr_is_closed = True finally: - self._is_closing = None + self._attr_is_closing = None self.async_write_ha_state() async def async_open_cover(self, **kwargs): """Open the cover.""" - self._is_opening = True + self._attr_is_opening = True self.async_write_ha_state() try: # Blocks until the open command is sent @@ -149,9 +104,9 @@ class SomfyShade(RestoreEntity, CoverEntity): await self.somfy_mylink.move_up(self._target_id) else: await self.somfy_mylink.move_down(self._target_id) - self._closed = False + self._attr_is_closed = False finally: - self._is_opening = None + self._attr_is_opening = None self.async_write_ha_state() async def async_stop_cover(self, **kwargs): @@ -168,4 +123,4 @@ class SomfyShade(RestoreEntity, CoverEntity): STATE_OPEN, STATE_CLOSED, ): - self._closed = last_state.state == STATE_CLOSED + self._attr_is_closed = last_state.state == STATE_CLOSED