Removing gogogate2 emulated cover transitional states. (#38199)

This commit is contained in:
Robert Van Gorkom 2020-07-25 12:43:45 -07:00 committed by GitHub
parent 1776540757
commit da380d89c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 63 deletions

View file

@ -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

View file

@ -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(