From 6b962a2207b483e5b5f3cd8b6fa1ede737da6d7c Mon Sep 17 00:00:00 2001 From: Eric Rolf Date: Thu, 11 Feb 2016 07:41:42 -0500 Subject: [PATCH] Updated coveragec, cleaned up constants, added test for demo. --- .coveragerc | 2 +- .../components/garage_door/__init__.py | 20 +++----- tests/components/garage_door/__init__.py | 0 tests/components/garage_door/test_demo.py | 51 +++++++++++++++++++ 4 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 tests/components/garage_door/__init__.py create mode 100644 tests/components/garage_door/test_demo.py diff --git a/.coveragerc b/.coveragerc index 3e24b33718c..068624b929a 100644 --- a/.coveragerc +++ b/.coveragerc @@ -149,7 +149,7 @@ omit = homeassistant/components/thermostat/honeywell.py homeassistant/components/thermostat/proliphix.py homeassistant/components/thermostat/radiotherm.py - + homeassistant/components/garage_door/wink.py [report] # Regexes for lines to exclude from consideration diff --git a/homeassistant/components/garage_door/__init__.py b/homeassistant/components/garage_door/__init__.py index 7854d33cb17..ebaa37a78c9 100644 --- a/homeassistant/components/garage_door/__init__.py +++ b/homeassistant/components/garage_door/__init__.py @@ -6,7 +6,7 @@ Component to interface with garage doors that can be controlled remotely. For more details about this component, please refer to the documentation at https://home-assistant.io/components/garage_door/ """ -from datetime import timedelta + import logging import os @@ -27,10 +27,6 @@ ENTITY_ID_ALL_GARAGE_DOORS = group.ENTITY_ID_FORMAT.format('all_garage_doors') ENTITY_ID_FORMAT = DOMAIN + '.{}' -ATTR_CLOSED = "closed" - -MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10) - # Maps discovered services to their platforms DISCOVERY_PLATFORMS = { wink.DISCOVER_GARAGE_DOORS: 'wink' @@ -38,20 +34,19 @@ DISCOVERY_PLATFORMS = { _LOGGER = logging.getLogger(__name__) - def is_closed(hass, entity_id=None): """ Returns if the garage door is closed based on the statemachine. """ entity_id = entity_id or ENTITY_ID_ALL_GARAGE_DOORS return hass.states.is_state(entity_id, STATE_CLOSED) -def close_door(hass, entity_id=None): +def close(hass, entity_id=None): """ Closes all or specified garage door. """ data = {ATTR_ENTITY_ID: entity_id} if entity_id else None hass.services.call(DOMAIN, SERVICE_CLOSE, data) -def open_door(hass, entity_id=None): +def open(hass, entity_id=None): """ Open all or specified garage door. """ data = {ATTR_ENTITY_ID: entity_id} if entity_id else None hass.services.call(DOMAIN, SERVICE_OPEN, data) @@ -70,9 +65,9 @@ def setup(hass, config): for item in target_locks: if service.service == SERVICE_CLOSE: - item.close_door() + item.close() else: - item.open_door() + item.open() if item.should_poll: item.update_ha_state(True) @@ -96,11 +91,11 @@ class GarageDoorDevice(Entity): """ Is the garage door closed or opened. """ return None - def close_door(self): + def close(self): """ Closes the garage door. """ raise NotImplementedError() - def open_door(self): + def open(self): """ Opens the garage door. """ raise NotImplementedError() @@ -110,3 +105,4 @@ class GarageDoorDevice(Entity): if closed is None: return STATE_UNKNOWN return STATE_CLOSED if closed else STATE_OPEN + diff --git a/tests/components/garage_door/__init__.py b/tests/components/garage_door/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/components/garage_door/test_demo.py b/tests/components/garage_door/test_demo.py new file mode 100644 index 00000000000..f52aaa303d3 --- /dev/null +++ b/tests/components/garage_door/test_demo.py @@ -0,0 +1,51 @@ +""" +tests.components.garage_door.test_demo +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Tests demo garage door component. +""" +import unittest + +import homeassistant.core as ha +from homeassistant.components import garage_door + + +LEFT = 'garage_door.left_garage_door' +RIGHT = 'garage_door.right_garage_door' + + +class TestGarageDoorDemo(unittest.TestCase): + """ Test the demo garage door. """ + + def setUp(self): # pylint: disable=invalid-name + self.hass = ha.HomeAssistant() + self.assertTrue(garage_door.setup(self.hass, { + 'garage_door': { + 'platform': 'demo' + } + })) + + def tearDown(self): # pylint: disable=invalid-name + """ Stop down stuff we started. """ + self.hass.stop() + + def test_is_closed(self): + self.assertTrue(garage_door.is_closed(self.hass, LEFT)) + self.hass.states.is_state(LEFT, 'close') + + self.assertFalse(garage_door.is_closed(self.hass, RIGHT)) + self.hass.states.is_state(RIGHT, 'open') + + def test_open_door(self): + garage_door.open_door(self.hass, LEFT) + + self.hass.pool.block_till_done() + + self.assertFalse(garage_door.is_closed(self.hass, LEFT)) + + def test_close_door(self): + garage_door.close_door(self.hass, RIGHT) + + self.hass.pool.block_till_done() + + self.assertTrue(garage_door.is_closed(self.hass, RIGHT))