From da380d89c21b87a1e40e97933cb6fd450135a507 Mon Sep 17 00:00:00 2001 From: Robert Van Gorkom Date: Sat, 25 Jul 2020 12:43:45 -0700 Subject: [PATCH] Removing gogogate2 emulated cover transitional states. (#38199) --- homeassistant/components/gogogate2/cover.py | 35 +-------------------- tests/components/gogogate2/test_cover.py | 34 +++----------------- 2 files changed, 6 insertions(+), 63 deletions(-) diff --git a/homeassistant/components/gogogate2/cover.py b/homeassistant/components/gogogate2/cover.py index 05fed7621d4..a26bdbc3c8e 100644 --- a/homeassistant/components/gogogate2/cover.py +++ b/homeassistant/components/gogogate2/cover.py @@ -1,5 +1,4 @@ """Support for Gogogate2 garage Doors.""" -from datetime import datetime, timedelta import logging from typing import Callable, List, Optional @@ -13,13 +12,7 @@ from homeassistant.components.cover import ( CoverEntity, ) from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry -from homeassistant.const import ( - CONF_IP_ADDRESS, - CONF_PASSWORD, - CONF_USERNAME, - STATE_CLOSING, - STATE_OPENING, -) +from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD, CONF_USERNAME from homeassistant.core import HomeAssistant, callback import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity @@ -86,8 +79,6 @@ class Gogogate2Cover(CoverEntity): self._api = data_update_coordinator.api self._unique_id = cover_unique_id(config_entry, door) self._is_available = True - self._transition_state: Optional[str] = None - self._transition_state_start: Optional[datetime] = None @property def available(self) -> bool: @@ -119,16 +110,6 @@ class Gogogate2Cover(CoverEntity): return None - @property - def is_opening(self): - """Return if the cover is opening or not.""" - return self._transition_state == STATE_OPENING - - @property - def is_closing(self): - """Return if the cover is closing or not.""" - return self._transition_state == STATE_CLOSING - @property def device_class(self): """Return the class of this device, from component DEVICE_CLASSES.""" @@ -142,14 +123,10 @@ class Gogogate2Cover(CoverEntity): async def async_open_cover(self, **kwargs): """Open the door.""" await self.hass.async_add_executor_job(self._api.open_door, self._door.door_id) - self._transition_state = STATE_OPENING - self._transition_state_start = datetime.now() async def async_close_cover(self, **kwargs): """Close the door.""" await self.hass.async_add_executor_job(self._api.close_door, self._door.door_id) - self._transition_state = STATE_CLOSING - self._transition_state_start = datetime.now() @property def state_attributes(self): @@ -168,16 +145,6 @@ class Gogogate2Cover(CoverEntity): door = get_door_by_id(self._door.door_id, self._data_update_coordinator.data) - # Check if the transition state should expire. - if self._transition_state: - is_transition_state_expired = ( - datetime.now() - self._transition_state_start - ) > timedelta(seconds=60) - - if is_transition_state_expired or self._door.status != door.status: - self._transition_state = None - self._transition_state_start = None - # Set the state. self._door = door self._is_available = True diff --git a/tests/components/gogogate2/test_cover.py b/tests/components/gogogate2/test_cover.py index 8cffec47e65..5bc9ed9ebd4 100644 --- a/tests/components/gogogate2/test_cover.py +++ b/tests/components/gogogate2/test_cover.py @@ -1,7 +1,4 @@ """Tests for the GogoGate2 component.""" -from datetime import datetime, timedelta -from unittest.mock import MagicMock, patch - from gogogate2_api import GogoGate2Api from gogogate2_api.common import ( ActivateResponse, @@ -24,15 +21,15 @@ from homeassistant.const import ( CONF_PLATFORM, CONF_USERNAME, STATE_CLOSED, - STATE_CLOSING, STATE_OPEN, - STATE_OPENING, STATE_UNAVAILABLE, ) from homeassistant.core import HomeAssistant from .common import ComponentFactory +from tests.async_mock import MagicMock + async def test_import_fail( hass: HomeAssistant, component_factory: ComponentFactory @@ -405,11 +402,6 @@ async def test_open_close( ) await hass.async_block_till_done() component_data.api.close_door.assert_called_with(1) - await hass.services.async_call( - HA_DOMAIN, "update_entity", service_data={"entity_id": "cover.door1"}, - ) - await hass.async_block_till_done() - assert hass.states.get("cover.door1").state == STATE_CLOSING component_data.data_update_coordinator.api.info.return_value = closed_door_response await component_data.data_update_coordinator.async_refresh() @@ -422,35 +414,19 @@ async def test_open_close( ) await hass.async_block_till_done() component_data.api.open_door.assert_called_with(1) - await hass.services.async_call( - HA_DOMAIN, "update_entity", service_data={"entity_id": "cover.door1"}, - ) - await hass.async_block_till_done() - assert hass.states.get("cover.door1").state == STATE_OPENING # Assert the mid state does not change when the same status is returned. component_data.data_update_coordinator.api.info.return_value = closed_door_response await component_data.data_update_coordinator.async_refresh() component_data.data_update_coordinator.api.info.return_value = closed_door_response + await component_data.data_update_coordinator.async_refresh() + await component_data.data_update_coordinator.async_refresh() await hass.services.async_call( HA_DOMAIN, "update_entity", service_data={"entity_id": "cover.door1"}, ) await hass.async_block_till_done() - assert hass.states.get("cover.door1").state == STATE_OPENING - - # Assert the mid state times out. - with patch("homeassistant.components.gogogate2.cover.datetime") as datetime_mock: - datetime_mock.now.return_value = datetime.now() + timedelta(seconds=60.1) - component_data.data_update_coordinator.api.info.return_value = ( - closed_door_response - ) - await component_data.data_update_coordinator.async_refresh() - await hass.services.async_call( - HA_DOMAIN, "update_entity", service_data={"entity_id": "cover.door1"}, - ) - await hass.async_block_till_done() - assert hass.states.get("cover.door1").state == STATE_CLOSED + assert hass.states.get("cover.door1").state == STATE_CLOSED async def test_availability(