def test_roller_commands(mock_network, mock_openzwave):
    """Test position changed."""
    node = MockNode()
    value = MockValue(data=50, node=node,
                      command_class=const.COMMAND_CLASS_SWITCH_MULTILEVEL)
    open_value = MockValue(data=False, node=node)
    close_value = MockValue(data=False, node=node)
    values = MockEntityValues(primary=value, open=open_value,
                              close=close_value, node=node)
    device = zwave.get_device(node=node, values=values, node_config={})

    device.set_cover_position(25)
    assert node.set_dimmer.called
    value_id, brightness = node.set_dimmer.mock_calls[0][1]
    assert value_id == value.value_id
    assert brightness == 25

    device.open_cover()
    assert mock_network.manager.pressButton.called
    value_id, = mock_network.manager.pressButton.mock_calls.pop(0)[1]
    assert value_id == open_value.value_id

    device.close_cover()
    assert mock_network.manager.pressButton.called
    value_id, = mock_network.manager.pressButton.mock_calls.pop(0)[1]
    assert value_id == close_value.value_id

    device.stop_cover()
    assert mock_network.manager.releaseButton.called
    value_id, = mock_network.manager.releaseButton.mock_calls.pop(0)[1]
    assert value_id == open_value.value_id
def test_roller_reverse_open_close(mock_network, mock_openzwave):
    """Test position changed."""
    node = MockNode(manufacturer_id='010f', product_type='0301')
    value = MockValue(data=50, node=node,
                      command_class=const.COMMAND_CLASS_SWITCH_MULTILEVEL)
    open_value = MockValue(data=False, node=node)
    close_value = MockValue(data=False, node=node)
    values = MockEntityValues(primary=value, open=open_value,
                              close=close_value, node=node)
    device = zwave.get_device(node=node, values=values, node_config={})

    device.open_cover()
    assert mock_network.manager.pressButton.called
    value_id, = mock_network.manager.pressButton.mock_calls.pop(0)[1]
    assert value_id == close_value.value_id

    device.close_cover()
    assert mock_network.manager.pressButton.called
    value_id, = mock_network.manager.pressButton.mock_calls.pop(0)[1]
    assert value_id == open_value.value_id

    device.stop_cover()
    assert mock_network.manager.releaseButton.called
    value_id, = mock_network.manager.releaseButton.mock_calls.pop(0)[1]
    assert value_id == close_value.value_id
Example #3
0
def test_roller_value_changed(mock_openzwave):
    """Test position changed."""
    node = MockNode()
    value = MockValue(data=None, node=node,
                      command_class=const.COMMAND_CLASS_SWITCH_MULTILEVEL)
    values = MockEntityValues(primary=value, open=None, close=None, node=node)
    device = zwave.get_device(node=node, values=values, node_config={})

    assert device.current_cover_position is None
    assert device.is_closed is None

    value.data = 2
    value_changed(value)

    assert device.current_cover_position == 0
    assert device.is_closed

    value.data = 35
    value_changed(value)

    assert device.current_cover_position == 35
    assert not device.is_closed

    value.data = 97
    value_changed(value)

    assert device.current_cover_position == 100
    assert not device.is_closed
Example #4
0
def test_roller_reverse_open_close(hass, mock_openzwave):
    """Test position changed."""
    mock_network = hass.data[zwave.zwave.ZWAVE_NETWORK] = MagicMock()
    node = MockNode()
    value = MockValue(data=50, node=node,
                      command_class=const.COMMAND_CLASS_SWITCH_MULTILEVEL)
    open_value = MockValue(data=False, node=node)
    close_value = MockValue(data=False, node=node)
    values = MockEntityValues(primary=value, open=open_value,
                              close=close_value, node=node)
    device = zwave.get_device(
        hass=hass,
        node=node,
        values=values,
        node_config={zwave.zwave.CONF_INVERT_OPENCLOSE_BUTTONS: True})

    device.open_cover()
    assert mock_network.manager.pressButton.called
    value_id, = mock_network.manager.pressButton.mock_calls.pop(0)[1]
    assert value_id == close_value.value_id

    device.close_cover()
    assert mock_network.manager.pressButton.called
    value_id, = mock_network.manager.pressButton.mock_calls.pop(0)[1]
    assert value_id == open_value.value_id

    device.stop_cover()
    assert mock_network.manager.releaseButton.called
    value_id, = mock_network.manager.releaseButton.mock_calls.pop(0)[1]
    assert value_id == close_value.value_id
Example #5
0
def test_barrier_garage_value_changed(hass, mock_openzwave):
    """Test position changed."""
    node = MockNode()
    value = MockValue(data="Closed", node=node,
                      command_class=const.COMMAND_CLASS_BARRIER_OPERATOR)
    values = MockEntityValues(primary=value, node=node)
    device = zwave.get_device(hass=hass, node=node, values=values,
                              node_config={})

    assert device.is_closed
    assert not device.is_opening
    assert not device.is_closing

    value.data = "Opening"
    value_changed(value)
    assert not device.is_closed
    assert device.is_opening
    assert not device.is_closing

    value.data = "Opened"
    value_changed(value)
    assert not device.is_closed
    assert not device.is_opening
    assert not device.is_closing

    value.data = "Closing"
    value_changed(value)
    assert not device.is_closed
    assert not device.is_opening
    assert device.is_closing
Example #6
0
def test_barrier_garage_value_changed(hass, mock_openzwave):
    """Test position changed."""
    node = MockNode()
    value = MockValue(data="Closed",
                      node=node,
                      command_class=const.COMMAND_CLASS_BARRIER_OPERATOR)
    values = MockEntityValues(primary=value, node=node)
    device = zwave.get_device(hass=hass,
                              node=node,
                              values=values,
                              node_config={})

    assert device.is_closed
    assert not device.is_opening
    assert not device.is_closing

    value.data = "Opening"
    value_changed(value)
    assert not device.is_closed
    assert device.is_opening
    assert not device.is_closing

    value.data = "Opened"
    value_changed(value)
    assert not device.is_closed
    assert not device.is_opening
    assert not device.is_closing

    value.data = "Closing"
    value_changed(value)
    assert not device.is_closed
    assert not device.is_opening
    assert device.is_closing
Example #7
0
def test_roller_reverse_open_close(hass, mock_openzwave):
    """Test position changed."""
    mock_network = hass.data[zwave.zwave.DATA_NETWORK] = MagicMock()
    node = MockNode()
    value = MockValue(data=50,
                      node=node,
                      command_class=const.COMMAND_CLASS_SWITCH_MULTILEVEL)
    open_value = MockValue(data=False, node=node)
    close_value = MockValue(data=False, node=node)
    values = MockEntityValues(primary=value,
                              open=open_value,
                              close=close_value,
                              node=node)
    device = zwave.get_device(
        hass=hass,
        node=node,
        values=values,
        node_config={zwave.zwave.CONF_INVERT_OPENCLOSE_BUTTONS: True})

    device.open_cover()
    assert mock_network.manager.pressButton.called
    value_id, = mock_network.manager.pressButton.mock_calls.pop(0)[1]
    assert value_id == close_value.value_id

    device.close_cover()
    assert mock_network.manager.pressButton.called
    value_id, = mock_network.manager.pressButton.mock_calls.pop(0)[1]
    assert value_id == open_value.value_id

    device.stop_cover()
    assert mock_network.manager.releaseButton.called
    value_id, = mock_network.manager.releaseButton.mock_calls.pop(0)[1]
    assert value_id == close_value.value_id
Example #8
0
def test_roller_value_changed(hass, mock_openzwave):
    """Test position changed."""
    hass.data[zwave.zwave.DATA_NETWORK] = MagicMock()
    node = MockNode()
    value = MockValue(data=None,
                      node=node,
                      command_class=const.COMMAND_CLASS_SWITCH_MULTILEVEL)
    values = MockEntityValues(primary=value, open=None, close=None, node=node)
    device = zwave.get_device(hass=hass,
                              node=node,
                              values=values,
                              node_config={})

    assert device.current_cover_position is None
    assert device.is_closed is None

    value.data = 2
    value_changed(value)

    assert device.current_cover_position == 0
    assert device.is_closed

    value.data = 35
    value_changed(value)

    assert device.current_cover_position == 35
    assert not device.is_closed

    value.data = 97
    value_changed(value)

    assert device.current_cover_position == 100
    assert not device.is_closed
def test_get_device_detects_none(mock_openzwave):
    """Test device returns none."""
    node = MockNode()
    value = MockValue(data=0, node=node)
    values = MockEntityValues(primary=value, node=node)

    device = zwave.get_device(node=node, values=values, node_config={})
    assert device is None
Example #10
0
def test_roller_no_position_workaround(mock_openzwave):
    """Test position changed."""
    node = MockNode(manufacturer_id='0047', product_type='5a52')
    value = MockValue(data=45, node=node,
                      command_class=const.COMMAND_CLASS_SWITCH_MULTILEVEL)
    values = MockEntityValues(primary=value, open=None, close=None, node=node)
    device = zwave.get_device(node=node, values=values, node_config={})

    assert device.current_cover_position is None
Example #11
0
def test_get_device_detects_rollershutter(mock_openzwave):
    """Test device returns rollershutter."""
    node = MockNode()
    value = MockValue(data=0, node=node,
                      command_class=const.COMMAND_CLASS_SWITCH_MULTILEVEL)
    values = MockEntityValues(primary=value, open=None, close=None, node=node)

    device = zwave.get_device(node=node, values=values, node_config={})
    assert isinstance(device, zwave.ZwaveRollershutter)
Example #12
0
def test_get_device_detects_garagedoor(mock_openzwave):
    """Test device returns garage door."""
    node = MockNode()
    value = MockValue(data=0, node=node,
                      command_class=const.COMMAND_CLASS_BARRIER_OPERATOR)
    values = MockEntityValues(primary=value, node=node)

    device = zwave.get_device(node=node, values=values, node_config={})
    assert isinstance(device, zwave.ZwaveGarageDoor)
    assert device.device_class == "garage"
    assert device.supported_features == SUPPORT_OPEN | SUPPORT_CLOSE
def test_get_device_detects_garagedoor_switch(hass, mock_openzwave):
    """Test device returns garage door."""
    node = MockNode()
    value = MockValue(data=False, node=node,
                      command_class=const.COMMAND_CLASS_SWITCH_BINARY)
    values = MockEntityValues(primary=value, node=node)

    device = zwave.get_device(hass=hass, node=node, values=values,
                              node_config={})
    assert isinstance(device, zwave.ZwaveGarageDoorSwitch)
    assert device.device_class == "garage"
    assert device.supported_features == SUPPORT_OPEN | SUPPORT_CLOSE
Example #14
0
def test_get_device_detects_garagedoor_switch(hass, mock_openzwave):
    """Test device returns garage door."""
    node = MockNode()
    value = MockValue(data=False, node=node,
                      command_class=const.COMMAND_CLASS_SWITCH_BINARY)
    values = MockEntityValues(primary=value, node=node)

    device = zwave.get_device(hass=hass, node=node, values=values,
                              node_config={})
    assert isinstance(device, zwave.ZwaveGarageDoorSwitch)
    assert device.device_class == "garage"
    assert device.supported_features == SUPPORT_OPEN | SUPPORT_CLOSE
Example #15
0
def test_garage_commands(mock_openzwave):
    """Test position changed."""
    node = MockNode()
    value = MockValue(data=False, node=node,
                      command_class=const.COMMAND_CLASS_BARRIER_OPERATOR)
    values = MockEntityValues(primary=value, node=node)
    device = zwave.get_device(node=node, values=values, node_config={})

    assert value.data is False
    device.open_cover()
    assert value.data is True
    device.close_cover()
    assert value.data is False
def test_switch_garage_commands(hass, mock_openzwave):
    """Test position changed."""
    node = MockNode()
    value = MockValue(data=False, node=node,
                      command_class=const.COMMAND_CLASS_SWITCH_BINARY)
    values = MockEntityValues(primary=value, node=node)
    device = zwave.get_device(hass=hass, node=node, values=values,
                              node_config={})

    assert value.data is False
    device.open_cover()
    assert value.data is True
    device.close_cover()
    assert value.data is False
Example #17
0
def test_switch_garage_commands(hass, mock_openzwave):
    """Test position changed."""
    node = MockNode()
    value = MockValue(data=False, node=node,
                      command_class=const.COMMAND_CLASS_SWITCH_BINARY)
    values = MockEntityValues(primary=value, node=node)
    device = zwave.get_device(hass=hass, node=node, values=values,
                              node_config={})

    assert value.data is False
    device.open_cover()
    assert value.data is True
    device.close_cover()
    assert value.data is False