core/homeassistant/components/garage_door/demo.py

52 lines
1.4 KiB
Python
Raw Normal View History

2016-02-01 02:39:04 +00:00
"""
Demo garage door platform that has two fake doors.
For more details about this platform, please refer to the documentation
https://home-assistant.io/components/demo/
2016-02-01 02:39:04 +00:00
"""
from homeassistant.components.garage_door import GarageDoorDevice
from homeassistant.const import STATE_CLOSED, STATE_OPEN
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Setup demo garage door platform."""
2016-02-01 02:39:04 +00:00
add_devices_callback([
DemoGarageDoor('Left Garage Door', STATE_CLOSED),
DemoGarageDoor('Right Garage Door', STATE_OPEN)
])
class DemoGarageDoor(GarageDoorDevice):
"""Provides a demo garage door."""
2016-03-07 20:22:21 +00:00
2016-02-01 02:39:04 +00:00
def __init__(self, name, state):
2016-03-07 20:22:21 +00:00
"""Initialize the garage door."""
2016-02-01 02:39:04 +00:00
self._name = name
self._state = state
@property
def should_poll(self):
"""No polling needed for a demo garage door."""
2016-02-01 02:39:04 +00:00
return False
@property
def name(self):
"""Return the name of the device if any."""
2016-02-01 02:39:04 +00:00
return self._name
@property
def is_closed(self):
"""Return true if garage door is closed."""
2016-02-01 02:39:04 +00:00
return self._state == STATE_CLOSED
2016-02-05 20:16:56 +00:00
def close_door(self, **kwargs):
"""Close the garage door."""
2016-02-01 02:39:04 +00:00
self._state = STATE_CLOSED
self.update_ha_state()
2016-02-05 20:16:56 +00:00
def open_door(self, **kwargs):
"""Open the garage door."""
2016-02-01 02:39:04 +00:00
self._state = STATE_OPEN
self.update_ha_state()