mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Add position to zwave rollershutter (#2772)
This commit is contained in:
parent
693098ff00
commit
7762365b3f
@ -16,7 +16,7 @@ from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
|||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.components import group
|
from homeassistant.components import group
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
SERVICE_MOVE_UP, SERVICE_MOVE_DOWN, SERVICE_STOP,
|
SERVICE_MOVE_UP, SERVICE_MOVE_DOWN, SERVICE_MOVE_POSITION, SERVICE_STOP,
|
||||||
STATE_OPEN, STATE_CLOSED, STATE_UNKNOWN, ATTR_ENTITY_ID)
|
STATE_OPEN, STATE_CLOSED, STATE_UNKNOWN, ATTR_ENTITY_ID)
|
||||||
|
|
||||||
|
|
||||||
@ -32,11 +32,17 @@ ENTITY_ID_FORMAT = DOMAIN + '.{}'
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ATTR_CURRENT_POSITION = 'current_position'
|
ATTR_CURRENT_POSITION = 'current_position'
|
||||||
|
ATTR_POSITION = 'position'
|
||||||
|
|
||||||
ROLLERSHUTTER_SERVICE_SCHEMA = vol.Schema({
|
ROLLERSHUTTER_SERVICE_SCHEMA = vol.Schema({
|
||||||
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
|
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ROLLERSHUTTER_MOVE_POSITION_SCHEMA = ROLLERSHUTTER_SERVICE_SCHEMA.extend({
|
||||||
|
vol.Required(ATTR_POSITION):
|
||||||
|
vol.All(vol.Coerce(int), vol.Range(min=0, max=100)),
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def is_open(hass, entity_id=None):
|
def is_open(hass, entity_id=None):
|
||||||
"""Return if the roller shutter is open based on the statemachine."""
|
"""Return if the roller shutter is open based on the statemachine."""
|
||||||
@ -56,6 +62,13 @@ def move_down(hass, entity_id=None):
|
|||||||
hass.services.call(DOMAIN, SERVICE_MOVE_DOWN, data)
|
hass.services.call(DOMAIN, SERVICE_MOVE_DOWN, data)
|
||||||
|
|
||||||
|
|
||||||
|
def move_position(hass, position, entity_id=None):
|
||||||
|
"""Move to specific position all or specified roller shutter."""
|
||||||
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||||
|
data[ATTR_POSITION] = position
|
||||||
|
hass.services.call(DOMAIN, SERVICE_MOVE_POSITION, data)
|
||||||
|
|
||||||
|
|
||||||
def stop(hass, entity_id=None):
|
def stop(hass, entity_id=None):
|
||||||
"""Stop all or specified roller shutter."""
|
"""Stop all or specified roller shutter."""
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||||
@ -77,6 +90,8 @@ def setup(hass, config):
|
|||||||
rollershutter.move_up()
|
rollershutter.move_up()
|
||||||
elif service.service == SERVICE_MOVE_DOWN:
|
elif service.service == SERVICE_MOVE_DOWN:
|
||||||
rollershutter.move_down()
|
rollershutter.move_down()
|
||||||
|
elif service.service == SERVICE_MOVE_POSITION:
|
||||||
|
rollershutter.move_position(service.data[ATTR_POSITION])
|
||||||
elif service.service == SERVICE_STOP:
|
elif service.service == SERVICE_STOP:
|
||||||
rollershutter.stop()
|
rollershutter.stop()
|
||||||
|
|
||||||
@ -94,6 +109,10 @@ def setup(hass, config):
|
|||||||
handle_rollershutter_service,
|
handle_rollershutter_service,
|
||||||
descriptions.get(SERVICE_MOVE_DOWN),
|
descriptions.get(SERVICE_MOVE_DOWN),
|
||||||
schema=ROLLERSHUTTER_SERVICE_SCHEMA)
|
schema=ROLLERSHUTTER_SERVICE_SCHEMA)
|
||||||
|
hass.services.register(DOMAIN, SERVICE_MOVE_POSITION,
|
||||||
|
handle_rollershutter_service,
|
||||||
|
descriptions.get(SERVICE_MOVE_POSITION),
|
||||||
|
schema=ROLLERSHUTTER_MOVE_POSITION_SCHEMA)
|
||||||
hass.services.register(DOMAIN, SERVICE_STOP,
|
hass.services.register(DOMAIN, SERVICE_STOP,
|
||||||
handle_rollershutter_service,
|
handle_rollershutter_service,
|
||||||
descriptions.get(SERVICE_STOP),
|
descriptions.get(SERVICE_STOP),
|
||||||
@ -143,6 +162,10 @@ class RollershutterDevice(Entity):
|
|||||||
"""Move the roller shutter up."""
|
"""Move the roller shutter up."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def move_position(self, **kwargs):
|
||||||
|
"""Move the roller shutter to a specific position."""
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
def stop(self, **kwargs):
|
def stop(self, **kwargs):
|
||||||
"""Stop the roller shutter."""
|
"""Stop the roller shutter."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
@ -32,6 +32,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
add_devices_callback(devices)
|
add_devices_callback(devices)
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=abstract-method
|
||||||
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
||||||
class CommandRollershutter(RollershutterDevice):
|
class CommandRollershutter(RollershutterDevice):
|
||||||
"""Representation a command line roller shutter."""
|
"""Representation a command line roller shutter."""
|
||||||
|
@ -60,6 +60,14 @@ class DemoRollershutter(RollershutterDevice):
|
|||||||
self._listen()
|
self._listen()
|
||||||
self._moving_up = False
|
self._moving_up = False
|
||||||
|
|
||||||
|
def move_position(self, position, **kwargs):
|
||||||
|
"""Move the roller shutter to a specific position."""
|
||||||
|
if self._position == position:
|
||||||
|
return
|
||||||
|
|
||||||
|
self._listen()
|
||||||
|
self._moving_up = position < self._position
|
||||||
|
|
||||||
def stop(self, **kwargs):
|
def stop(self, **kwargs):
|
||||||
"""Stop the roller shutter."""
|
"""Stop the roller shutter."""
|
||||||
if self._listener is not None:
|
if self._listener is not None:
|
||||||
|
@ -30,6 +30,7 @@ def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
|||||||
add_callback_devices)
|
add_callback_devices)
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=abstract-method
|
||||||
class HMRollershutter(homematic.HMDevice, RollershutterDevice):
|
class HMRollershutter(homematic.HMDevice, RollershutterDevice):
|
||||||
"""Represents a Homematic Rollershutter in Home Assistant."""
|
"""Represents a Homematic Rollershutter in Home Assistant."""
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
)])
|
)])
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=abstract-method
|
||||||
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
||||||
class MqttRollershutter(RollershutterDevice):
|
class MqttRollershutter(RollershutterDevice):
|
||||||
"""Representation of a roller shutter that can be controlled using MQTT."""
|
"""Representation of a roller shutter that can be controlled using MQTT."""
|
||||||
|
@ -40,6 +40,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
rfxtrx.RECEIVED_EVT_SUBSCRIBERS.append(rollershutter_update)
|
rfxtrx.RECEIVED_EVT_SUBSCRIBERS.append(rollershutter_update)
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=abstract-method
|
||||||
class RfxtrxRollershutter(rfxtrx.RfxtrxDevice, RollershutterDevice):
|
class RfxtrxRollershutter(rfxtrx.RfxtrxDevice, RollershutterDevice):
|
||||||
"""Representation of an rfxtrx roller shutter."""
|
"""Representation of an rfxtrx roller shutter."""
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
add_devices_callback(rollershutters)
|
add_devices_callback(rollershutters)
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=abstract-method
|
||||||
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
||||||
class SCSGateRollerShutter(RollershutterDevice):
|
class SCSGateRollerShutter(RollershutterDevice):
|
||||||
"""Representation of SCSGate rollershutter."""
|
"""Representation of SCSGate rollershutter."""
|
||||||
|
@ -14,6 +14,14 @@ move_down:
|
|||||||
description: Name(s) of roller shutter(s) to move down
|
description: Name(s) of roller shutter(s) to move down
|
||||||
example: 'rollershutter.living_room'
|
example: 'rollershutter.living_room'
|
||||||
|
|
||||||
|
move_position:
|
||||||
|
description: Move to specific position all or specified roller shutter
|
||||||
|
|
||||||
|
fields:
|
||||||
|
position:
|
||||||
|
description: Position of the rollershutter (0 to 100)
|
||||||
|
example: 30
|
||||||
|
|
||||||
stop:
|
stop:
|
||||||
description: Stop all or specified roller shutter
|
description: Stop all or specified roller shutter
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
pywink.get_shades())
|
pywink.get_shades())
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=abstract-method
|
||||||
class WinkRollershutterDevice(WinkDevice, RollershutterDevice):
|
class WinkRollershutterDevice(WinkDevice, RollershutterDevice):
|
||||||
"""Representation of a Wink rollershutter (shades)."""
|
"""Representation of a Wink rollershutter (shades)."""
|
||||||
|
|
||||||
|
@ -97,6 +97,10 @@ class ZwaveRollershutter(zwave.ZWaveDeviceEntity, RollershutterDevice):
|
|||||||
self._lozwmgr.pressButton(value.value_id)
|
self._lozwmgr.pressButton(value.value_id)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def move_position(self, position, **kwargs):
|
||||||
|
"""Move the roller shutter to a specific position."""
|
||||||
|
self._node.set_dimmer(self._value.value_id, 100 - position)
|
||||||
|
|
||||||
def stop(self, **kwargs):
|
def stop(self, **kwargs):
|
||||||
"""Stop the roller shutter."""
|
"""Stop the roller shutter."""
|
||||||
for value in self._node.get_values(
|
for value in self._node.get_values(
|
||||||
|
@ -221,6 +221,7 @@ SERVICE_CLOSE = "close"
|
|||||||
|
|
||||||
SERVICE_MOVE_UP = 'move_up'
|
SERVICE_MOVE_UP = 'move_up'
|
||||||
SERVICE_MOVE_DOWN = 'move_down'
|
SERVICE_MOVE_DOWN = 'move_down'
|
||||||
|
SERVICE_MOVE_POSITION = 'move_position'
|
||||||
SERVICE_STOP = 'stop'
|
SERVICE_STOP = 'stop'
|
||||||
|
|
||||||
# #### API / REMOTE ####
|
# #### API / REMOTE ####
|
||||||
|
55
tests/components/rollershutter/test_demo.py
Normal file
55
tests/components/rollershutter/test_demo.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
"""The tests for the Demo roller shutter platform."""
|
||||||
|
import unittest
|
||||||
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
|
from homeassistant.components.rollershutter import demo
|
||||||
|
from tests.common import fire_time_changed, get_test_home_assistant
|
||||||
|
|
||||||
|
|
||||||
|
class TestRollershutterDemo(unittest.TestCase):
|
||||||
|
"""Test the Demo roller shutter."""
|
||||||
|
|
||||||
|
def setUp(self): # pylint: disable=invalid-name
|
||||||
|
"""Setup things to be run when tests are started."""
|
||||||
|
self.hass = get_test_home_assistant()
|
||||||
|
|
||||||
|
def tearDown(self): # pylint: disable=invalid-name
|
||||||
|
"""Stop down everything that was started."""
|
||||||
|
self.hass.stop()
|
||||||
|
|
||||||
|
def test_move_up(self):
|
||||||
|
"""Test moving the rollershutter up."""
|
||||||
|
entity = demo.DemoRollershutter(self.hass, 'test', 100)
|
||||||
|
entity.move_up()
|
||||||
|
|
||||||
|
fire_time_changed(self.hass, dt_util.utcnow())
|
||||||
|
self.hass.pool.block_till_done()
|
||||||
|
self.assertEqual(90, entity.current_position)
|
||||||
|
|
||||||
|
def test_move_down(self):
|
||||||
|
"""Test moving the rollershutter down."""
|
||||||
|
entity = demo.DemoRollershutter(self.hass, 'test', 0)
|
||||||
|
entity.move_down()
|
||||||
|
|
||||||
|
fire_time_changed(self.hass, dt_util.utcnow())
|
||||||
|
self.hass.pool.block_till_done()
|
||||||
|
self.assertEqual(10, entity.current_position)
|
||||||
|
|
||||||
|
def test_move_position(self):
|
||||||
|
"""Test moving the rollershutter to a specific position."""
|
||||||
|
entity = demo.DemoRollershutter(self.hass, 'test', 0)
|
||||||
|
entity.move_position(10)
|
||||||
|
|
||||||
|
fire_time_changed(self.hass, dt_util.utcnow())
|
||||||
|
self.hass.pool.block_till_done()
|
||||||
|
self.assertEqual(10, entity.current_position)
|
||||||
|
|
||||||
|
def test_stop(self):
|
||||||
|
"""Test stopping the rollershutter."""
|
||||||
|
entity = demo.DemoRollershutter(self.hass, 'test', 0)
|
||||||
|
entity.move_down()
|
||||||
|
entity.stop()
|
||||||
|
|
||||||
|
fire_time_changed(self.hass, dt_util.utcnow())
|
||||||
|
self.hass.pool.block_till_done()
|
||||||
|
self.assertEqual(0, entity.current_position)
|
Loading…
x
Reference in New Issue
Block a user