Skip to content

Commit

Permalink
Updated coveragec, cleaned up constants, added test for demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
xrolfex authored and Eric Rolf committed Feb 11, 2016
1 parent 18b3d3d commit 6b962a2
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 8 additions & 12 deletions homeassistant/components/garage_door/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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

Expand All @@ -27,31 +27,26 @@

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'
}

_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)
Expand All @@ -70,9 +65,9 @@ def handle_garage_door_service(service):

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)
Expand All @@ -96,11 +91,11 @@ def is_closed(self):
""" 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()

Expand All @@ -110,3 +105,4 @@ def state(self):
if closed is None:
return STATE_UNKNOWN
return STATE_CLOSED if closed else STATE_OPEN

Empty file.
51 changes: 51 additions & 0 deletions tests/components/garage_door/test_demo.py
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit 6b962a2

Please sign in to comment.