コード例 #1
0
async def test_trigger_sensor_value_changed(hass, mock_openzwave):
    """Test value changed for trigger sensor."""
    node = MockNode(
        manufacturer_id='013c', product_type='0002', product_id='0002')
    value = MockValue(data=False, node=node)
    value_off_delay = MockValue(data=15, node=node)
    values = MockEntityValues(primary=value, off_delay=value_off_delay)
    device = binary_sensor.get_device(node=node, values=values, node_config={})

    assert not device.is_on

    value.data = True
    await hass.async_add_job(value_changed, value)
    assert device.invalidate_after is None

    device.hass = hass

    value.data = True
    await hass.async_add_job(value_changed, value)
    assert device.is_on

    test_time = device.invalidate_after - datetime.timedelta(seconds=1)
    with patch('homeassistant.util.dt.utcnow', return_value=test_time):
        assert device.is_on

    test_time = device.invalidate_after
    with patch('homeassistant.util.dt.utcnow', return_value=test_time):
        assert not device.is_on
コード例 #2
0
ファイル: test_zwave.py プロジェクト: Martwall/home-assistant
async def test_get_protection_values_nonexisting_node(hass, client):
    """Test getting protection values on node with wrong nodeid."""
    network = hass.data[DATA_NETWORK] = MagicMock()
    node = MockNode(node_id=18,
                    command_classes=[const.COMMAND_CLASS_PROTECTION])
    value = MockValue(
        value_id=123456,
        index=0,
        instance=1,
        command_class=const.COMMAND_CLASS_PROTECTION)
    value.label = 'Protection Test'
    value.data_items = ['Unprotected', 'Protection by Sequence',
                        'No Operation Possible']
    value.data = 'Unprotected'
    network.nodes = {17: node}
    node.value = value

    resp = await client.get('/api/zwave/protection/18')

    assert resp.status == 404
    result = await resp.json()
    assert not node.get_protections.called
    assert not node.get_protection_item.called
    assert not node.get_protection_items.called
    assert result == {'message': 'Node not found'}
コード例 #3
0
def test_trigger_sensor_value_changed(hass, mock_openzwave):
    """Test value changed for trigger sensor."""
    node = MockNode(
        manufacturer_id='013c', product_type='0002', product_id='0002')
    value = MockValue(data=False, node=node)
    values = MockEntityValues(primary=value)
    device = zwave.get_device(node=node, values=values, node_config={})

    assert not device.is_on

    value.data = True
    yield from hass.loop.run_in_executor(None, value_changed, value)
    yield from hass.async_block_till_done()
    assert device.invalidate_after is None

    device.hass = hass

    value.data = True
    yield from hass.loop.run_in_executor(None, value_changed, value)
    yield from hass.async_block_till_done()
    assert device.is_on

    test_time = device.invalidate_after - datetime.timedelta(seconds=1)
    with patch('homeassistant.util.dt.utcnow', return_value=test_time):
        assert device.is_on

    test_time = device.invalidate_after
    with patch('homeassistant.util.dt.utcnow', return_value=test_time):
        assert not device.is_on
コード例 #4
0
def test_fan_value_changed(mock_openzwave):
    """Test value changed for zwave fan."""
    node = MockNode()
    value = MockValue(data=0, node=node)
    values = MockEntityValues(primary=value)
    device = zwave.get_device(node=node, values=values, node_config={})

    assert not device.is_on

    value.data = 10
    value_changed(value)

    assert device.is_on
    assert device.speed == SPEED_LOW

    value.data = 50
    value_changed(value)

    assert device.is_on
    assert device.speed == SPEED_MEDIUM

    value.data = 90
    value_changed(value)

    assert device.is_on
    assert device.speed == SPEED_HIGH
コード例 #5
0
ファイル: test_zwave.py プロジェクト: Martwall/home-assistant
async def test_set_protection_value_nonexisting_node(hass, client):
    """Test setting protection value on nonexisting node."""
    network = hass.data[DATA_NETWORK] = MagicMock()
    node = MockNode(node_id=17,
                    command_classes=[const.COMMAND_CLASS_PROTECTION])
    value = MockValue(
        value_id=123456,
        index=0,
        instance=1,
        command_class=const.COMMAND_CLASS_PROTECTION)
    value.label = 'Protection Test'
    value.data_items = ['Unprotected', 'Protection by Sequence',
                        'No Operation Possible']
    value.data = 'Unprotected'
    network.nodes = {17: node}
    node.value = value
    node.set_protection.return_value = False

    resp = await client.post(
        '/api/zwave/protection/18', data=json.dumps({
            'value_id': '123456', 'selection': 'Protecton by Seuence'}))

    assert resp.status == 404
    result = await resp.json()
    assert not node.set_protection.called
    assert result == {'message': 'Node not found'}
コード例 #6
0
ファイル: test_zwave.py プロジェクト: Martwall/home-assistant
async def test_get_protection_values(hass, client):
    """Test getting protection values on node."""
    network = hass.data[DATA_NETWORK] = MagicMock()
    node = MockNode(node_id=18,
                    command_classes=[const.COMMAND_CLASS_PROTECTION])
    value = MockValue(
        value_id=123456,
        index=0,
        instance=1,
        command_class=const.COMMAND_CLASS_PROTECTION)
    value.label = 'Protection Test'
    value.data_items = ['Unprotected', 'Protection by Sequence',
                        'No Operation Possible']
    value.data = 'Unprotected'
    network.nodes = {18: node}
    node.value = value

    node.get_protection_item.return_value = "Unprotected"
    node.get_protection_items.return_value = value.data_items
    node.get_protections.return_value = {value.value_id: 'Object'}

    resp = await client.get('/api/zwave/protection/18')

    assert resp.status == 200
    result = await resp.json()
    assert node.get_protections.called
    assert node.get_protection_item.called
    assert node.get_protection_items.called
    assert result == {
        'value_id': '123456',
        'selected': 'Unprotected',
        'options': ['Unprotected', 'Protection by Sequence',
                    'No Operation Possible']
    }
コード例 #7
0
ファイル: test_zwave.py プロジェクト: nunofgs/home-assistant
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
コード例 #8
0
ファイル: test_cover.py プロジェクト: arsaboo/home-assistant
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 = cover.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
コード例 #9
0
ファイル: test_api.py プロジェクト: tedstriker/home-assistant
def test_get_usercodes_no_genreuser(hass, test_client):
    """Test getting usercodes on node missing genre user."""
    app = mock_http_component_app(hass)
    ZWaveUserCodeView().register(app.router)

    network = hass.data[DATA_NETWORK] = MagicMock()
    node = MockNode(node_id=18,
                    command_classes=[const.COMMAND_CLASS_USER_CODE])
    value = MockValue(
        index=0,
        command_class=const.COMMAND_CLASS_USER_CODE)
    value.genre = const.GENRE_SYSTEM
    value.label = 'label'
    value.data = '1234'
    node.values = {0: value}
    network.nodes = {18: node}
    node.get_values.return_value = node.values

    client = yield from test_client(app)

    resp = yield from client.get('/api/zwave/usercodes/18')

    assert resp.status == 200
    result = yield from resp.json()

    assert result == {}
コード例 #10
0
ファイル: test_sensor.py プロジェクト: arsaboo/home-assistant
def test_alarm_sensor_value_changed(mock_openzwave):
    """Test value changed for Z-Wave sensor."""
    node = MockNode(command_classes=[const.COMMAND_CLASS_ALARM,
                                     const.COMMAND_CLASS_SENSOR_ALARM])
    value = MockValue(data=12.34, node=node, units='%')
    values = MockEntityValues(primary=value)

    device = sensor.get_device(node=node, values=values, node_config={})
    assert device.state == 12.34
    assert device.unit_of_measurement == '%'
    value.data = 45.67
    value_changed(value)
    assert device.state == 45.67
コード例 #11
0
ファイル: test_sensor.py プロジェクト: arsaboo/home-assistant
def test_multilevelsensor_value_changed_temp_celsius(mock_openzwave):
    """Test value changed for Z-Wave multilevel sensor for temperature."""
    node = MockNode(command_classes=[const.COMMAND_CLASS_SENSOR_MULTILEVEL,
                                     const.COMMAND_CLASS_METER])
    value = MockValue(data=38.85555, units='C', node=node)
    values = MockEntityValues(primary=value)

    device = sensor.get_device(node=node, values=values, node_config={})
    assert device.state == 38.9
    assert device.unit_of_measurement == homeassistant.const.TEMP_CELSIUS
    value.data = 37.95555
    value_changed(value)
    assert device.state == 38.0
コード例 #12
0
ファイル: test_sensor.py プロジェクト: arsaboo/home-assistant
def test_multilevelsensor_value_changed_integer(mock_openzwave):
    """Test value changed for Z-Wave multilevel sensor for other units."""
    node = MockNode(command_classes=[const.COMMAND_CLASS_SENSOR_MULTILEVEL,
                                     const.COMMAND_CLASS_METER])
    value = MockValue(data=5, units='counts', node=node)
    values = MockEntityValues(primary=value)

    device = sensor.get_device(node=node, values=values, node_config={})
    assert device.state == 5
    assert device.unit_of_measurement == 'counts'
    value.data = 6
    value_changed(value)
    assert device.state == 6
コード例 #13
0
def test_multilevelsensor_value_changed_temp_fahrenheit(mock_openzwave):
    """Test value changed for Z-Wave multilevel sensor for temperature."""
    node = MockNode(command_classes=[const.COMMAND_CLASS_SENSOR_MULTILEVEL,
                                     const.COMMAND_CLASS_METER])
    value = MockValue(data=190.95555, units='F', node=node)
    values = MockEntityValues(primary=value)

    device = zwave.get_device(node=node, values=values, node_config={})
    assert device.state == 191.0
    assert device.unit_of_measurement == homeassistant.const.TEMP_FAHRENHEIT
    value.data = 197.95555
    value_changed(value)
    assert device.state == 198.0
コード例 #14
0
def test_dimmer_value_changed(mock_openzwave):
    """Test value changed for dimmer lights."""
    node = MockNode()
    value = MockValue(data=0, node=node)
    device = zwave.get_device(node, value, {})

    assert not device.is_on

    value.data = 46
    value_changed(value)

    assert device.is_on
    assert device.brightness == 118
コード例 #15
0
ファイル: test_zwave.py プロジェクト: azogue/home-assistant
def test_switch_value_changed(mock_openzwave):
    """Test value changed for Z-Wave switch."""
    node = MockNode()
    value = MockValue(data=False, node=node)
    values = MockEntityValues(primary=value)
    device = zwave.get_device(node=node, values=values, node_config={})

    assert not device.is_on

    value.data = True
    value_changed(value)

    assert device.is_on
コード例 #16
0
def test_binary_sensor_value_changed(mock_openzwave):
    """Test value changed for binary sensor."""
    node = MockNode()
    value = MockValue(data=False, node=node,
                      command_class=const.COMMAND_CLASS_SENSOR_BINARY)
    values = MockEntityValues(primary=value)
    device = zwave.get_device(node=node, values=values, node_config={})

    assert not device.is_on

    value.data = True
    value_changed(value)

    assert device.is_on
コード例 #17
0
ファイル: test_cover.py プロジェクト: arsaboo/home-assistant
def test_switch_garage_value_changed(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 = cover.get_device(hass=hass, node=node, values=values,
                              node_config={})

    assert device.is_closed

    value.data = True
    value_changed(value)
    assert not device.is_closed
コード例 #18
0
ファイル: test_light.py プロジェクト: arsaboo/home-assistant
def test_dimmer_value_changed(mock_openzwave):
    """Test value changed for dimmer lights."""
    node = MockNode()
    value = MockValue(data=0, node=node)
    values = MockLightValues(primary=value)
    device = light.get_device(node=node, values=values, node_config={})

    assert not device.is_on

    value.data = 46
    value_changed(value)

    assert device.is_on
    assert device.brightness == 118
コード例 #19
0
ファイル: test_zwave.py プロジェクト: nunofgs/home-assistant
def test_garage_value_changed(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 device.is_closed

    value.data = True
    value_changed(value)

    assert not device.is_closed
コード例 #20
0
ファイル: test_api.py プロジェクト: tedstriker/home-assistant
def test_get_config(hass, test_client):
    """Test getting config on node."""
    app = mock_http_component_app(hass)
    ZWaveNodeConfigView().register(app.router)

    network = hass.data[DATA_NETWORK] = MagicMock()
    node = MockNode(node_id=2)
    value = MockValue(
        index=12,
        command_class=const.COMMAND_CLASS_CONFIGURATION)
    value.label = 'label'
    value.help = 'help'
    value.type = 'type'
    value.data = 'data'
    value.data_items = ['item1', 'item2']
    value.max = 'max'
    value.min = 'min'
    node.values = {12: value}
    network.nodes = {2: node}
    node.get_values.return_value = node.values

    client = yield from test_client(app)

    resp = yield from client.get('/api/zwave/config/2')

    assert resp.status == 200
    result = yield from resp.json()

    assert result == {'12': {'data': 'data',
                             'data_items': ['item1', 'item2'],
                             'help': 'help',
                             'label': 'label',
                             'max': 'max',
                             'min': 'min',
                             'type': 'type'}}
コード例 #21
0
ファイル: test_zwave.py プロジェクト: nunofgs/home-assistant
def test_rgbcw_value_changed(mock_openzwave):
    """Test value changed for rgb lights."""
    node = MockNode(command_classes=[const.COMMAND_CLASS_SWITCH_COLOR])
    value = MockValue(data=0, node=node)
    color = MockValue(data=b'#0000000000', node=node)
    # Suppoorts RGB, Cold White
    color_channels = MockValue(data=0x1e, node=node)
    values = MockLightValues(primary=value, color=color,
                             color_channels=color_channels)
    device = zwave.get_device(node=node, values=values, node_config={})

    assert device.rgb_color == [0, 0, 0]

    color.data = b'#c86400c800'
    value_changed(color)

    assert device.rgb_color == [200, 150, 100]
コード例 #22
0
ファイル: test_zwave.py プロジェクト: chuchock/home-assistant
def test_rgb_value_changed(mock_openzwave):
    """Test value changed for rgb lights."""
    node = MockNode(command_classes=[const.COMMAND_CLASS_SWITCH_COLOR])
    value = MockValue(data=0, node=node)
    color = MockValue(data='#0000000000', node=node)
    # Supports RGB only
    color_channels = MockValue(data=0x1c, node=node)
    values = MockLightValues(primary=value, color=color,
                             color_channels=color_channels)
    device = zwave.get_device(node=node, values=values, node_config={})

    assert device.hs_color == (0, 0)

    color.data = '#ffbf800000'
    value_changed(color)

    assert device.hs_color == (29.764, 49.804)
コード例 #23
0
ファイル: test_zwave.py プロジェクト: chuchock/home-assistant
def test_rgbww_value_changed(mock_openzwave):
    """Test value changed for rgb lights."""
    node = MockNode(command_classes=[const.COMMAND_CLASS_SWITCH_COLOR])
    value = MockValue(data=0, node=node)
    color = MockValue(data='#0000000000', node=node)
    # Supports RGB, Warm White
    color_channels = MockValue(data=0x1d, node=node)
    values = MockLightValues(primary=value, color=color,
                             color_channels=color_channels)
    device = zwave.get_device(node=node, values=values, node_config={})

    assert device.hs_color == (0, 0)
    assert device.white_value == 0

    color.data = '#c86400c800'
    value_changed(color)

    assert device.hs_color == (30, 100)
    assert device.white_value == 200
コード例 #24
0
async def test_lock_clear_usercode_service(hass, mock_openzwave):
    """Test the zwave lock clear_usercode service."""
    mock_network = hass.data[const.DATA_NETWORK] = MagicMock()
    node = MockNode(node_id=12)
    value0 = MockValue(data=None, node=node, index=0)
    value1 = MockValue(data="123", node=node, index=1)

    node.get_values.return_value = {value0.value_id: value0, value1.value_id: value1}

    mock_network.nodes = {node.node_id: node}

    await setup_ozw(hass, mock_openzwave)
    await hass.async_block_till_done()

    await hass.services.async_call(
        lock.DOMAIN,
        lock.SERVICE_CLEAR_USERCODE,
        {const.ATTR_NODE_ID: node.node_id, lock.ATTR_CODE_SLOT: 1},
    )
    await hass.async_block_till_done()

    assert value1.data == "\0\0\0"
コード例 #25
0
def test_lock_clear_usercode_service(hass, mock_openzwave):
    """Test the zwave lock clear_usercode service."""
    node = MockNode(node_id=12)
    value0 = MockValue(data=None, node=node, index=0)
    value1 = MockValue(data='123', node=node, index=1)
    yield from zwave.async_setup_platform(hass, {}, MagicMock())

    node.get_values.return_value = {
        value0.value_id: value0,
        value1.value_id: value1,
    }

    with patch.object(zwave.zwave, 'NETWORK') as mock_network:
        mock_network.nodes = {node.node_id: node}
        yield from hass.services.async_call(
            zwave.DOMAIN, zwave.SERVICE_CLEAR_USERCODE, {
                const.ATTR_NODE_ID: node.node_id,
                zwave.ATTR_CODE_SLOT: 1
            })
        yield from hass.async_block_till_done()

    assert value1.data == '\0\0\0'
コード例 #26
0
def test_lock_alarm_level(mock_openzwave):
    """Test alarm level for Z-Wave lock."""
    node = MockNode()
    values = MockEntityValues(
        primary=MockValue(data=None, node=node),
        access_control=None,
        alarm_type=MockValue(data=None, node=node),
        alarm_level=MockValue(data=None, node=node),
    )
    device = lock.get_device(node=node, values=values, node_config={})

    assert lock.ATTR_LOCK_STATUS not in device.extra_state_attributes

    values.alarm_type.data = 21
    values.alarm_level.data = 1
    value_changed(values.alarm_type)
    value_changed(values.alarm_level)
    assert (
        device.extra_state_attributes[lock.ATTR_LOCK_STATUS]
        == "Manually Locked by Key Cylinder or Inside thumb turn"
    )

    values.alarm_type.data = 18
    values.alarm_level.data = "alice"
    value_changed(values.alarm_type)
    value_changed(values.alarm_level)
    assert (
        device.extra_state_attributes[lock.ATTR_LOCK_STATUS]
        == "Locked with Keypad by user alice"
    )

    values.alarm_type.data = 161
    values.alarm_level.data = 1
    value_changed(values.alarm_type)
    value_changed(values.alarm_level)
    assert (
        device.extra_state_attributes[lock.ATTR_LOCK_STATUS]
        == "Tamper Alarm: Too many keypresses"
    )
コード例 #27
0
    def setUp(self):
        """Initialize values for this testcase class."""
        self.hass = get_test_home_assistant()
        self.hass.start()

        setup_component(self.hass, 'zwave', {'zwave': {}})
        self.hass.block_till_done()

        self.node = MockNode()
        self.mock_schema = {
            const.DISC_COMPONENT: 'mock_component',
            const.DISC_VALUES: {
                const.DISC_PRIMARY: {
                    const.DISC_COMMAND_CLASS: ['mock_primary_class'],
                },
                'secondary': {
                    const.DISC_COMMAND_CLASS: ['mock_secondary_class'],
                },
                'optional': {
                    const.DISC_COMMAND_CLASS: ['mock_optional_class'],
                    const.DISC_OPTIONAL: True,
                }
            }
        }
        self.primary = MockValue(command_class='mock_primary_class',
                                 node=self.node)
        self.secondary = MockValue(command_class='mock_secondary_class',
                                   node=self.node)
        self.duplicate_secondary = MockValue(
            command_class='mock_secondary_class', node=self.node)
        self.optional = MockValue(command_class='mock_optional_class',
                                  node=self.node)
        self.no_match_value = MockValue(command_class='mock_bad_class',
                                        node=self.node)

        self.entity_id = '{}.{}'.format('mock_component',
                                        zwave.object_id(self.primary))
        self.zwave_config = {}
        self.device_config = {self.entity_id: {}}
コード例 #28
0
def test_lock_set_usercode_service(hass, mock_openzwave):
    """Test the zwave lock set_usercode service."""
    mock_network = hass.data[zwave.zwave.ZWAVE_NETWORK] = MagicMock()
    node = MockNode(node_id=12)
    value0 = MockValue(data=None, node=node, index=0)
    value1 = MockValue(data=None, node=node, index=1)
    yield from zwave.async_setup_platform(
        hass, {}, MagicMock())

    node.get_values.return_value = {
        value0.value_id: value0,
        value1.value_id: value1,
    }

    mock_network.nodes = {
        node.node_id: node
    }
    yield from hass.services.async_call(
        zwave.DOMAIN, zwave.SERVICE_SET_USERCODE, {
            const.ATTR_NODE_ID: node.node_id,
            zwave.ATTR_USERCODE: '1234',
            zwave.ATTR_CODE_SLOT: 1,
            })
    yield from hass.async_block_till_done()

    assert value1.data == '1234'

    mock_network.nodes = {
        node.node_id: node
    }
    yield from hass.services.async_call(
        zwave.DOMAIN, zwave.SERVICE_SET_USERCODE, {
            const.ATTR_NODE_ID: node.node_id,
            zwave.ATTR_USERCODE: '12345',
            zwave.ATTR_CODE_SLOT: 1,
            })
    yield from hass.async_block_till_done()

    assert value1.data == '1234'
コード例 #29
0
def test_alarm_type_workaround(mock_openzwave):
    """Test value changed for Z-Wave lock using alarm type."""
    node = MockNode(manufacturer_id="0109", product_id="0000")
    values = MockEntityValues(
        primary=MockValue(data=True, node=node),
        access_control=None,
        alarm_type=MockValue(data=16, node=node),
        alarm_level=None,
    )
    device = lock.get_device(node=node, values=values)
    assert not device.is_locked

    values.alarm_type.data = 18
    value_changed(values.alarm_type)
    assert device.is_locked

    values.alarm_type.data = 19
    value_changed(values.alarm_type)
    assert not device.is_locked

    values.alarm_type.data = 21
    value_changed(values.alarm_type)
    assert device.is_locked

    values.alarm_type.data = 22
    value_changed(values.alarm_type)
    assert not device.is_locked

    values.alarm_type.data = 24
    value_changed(values.alarm_type)
    assert device.is_locked

    values.alarm_type.data = 25
    value_changed(values.alarm_type)
    assert not device.is_locked

    values.alarm_type.data = 27
    value_changed(values.alarm_type)
    assert device.is_locked
コード例 #30
0
def test_get_device_detects_zw098(mock_openzwave):
    """Test get_device returns a zw098 color light."""
    node = MockNode(
        manufacturer_id="0086",
        product_id="0062",
        command_classes=[const.COMMAND_CLASS_SWITCH_COLOR],
    )
    value = MockValue(data=0, node=node)
    values = MockLightValues(primary=value)
    device = light.get_device(node=node, values=values, node_config={})
    assert isinstance(device, light.ZwaveColorLight)
    assert device.supported_features == (SUPPORT_BRIGHTNESS | SUPPORT_COLOR
                                         | SUPPORT_COLOR_TEMP)
コード例 #31
0
    def test_reset_node_meters(self):
        """Test zwave reset_node_meters service."""
        value = MockValue(
            instance=1,
            index=8,
            data=99.5,
            command_class=const.COMMAND_CLASS_METER,
        )
        reset_value = MockValue(
            instance=1,
            index=33,
            command_class=const.COMMAND_CLASS_METER,
        )
        node = MockNode(node_id=14)
        node.values = {8: value, 33: reset_value}
        node.get_values.return_value = node.values
        self.zwave_network.nodes = {14: node}

        self.hass.services.call('zwave', 'reset_node_meters', {
            const.ATTR_NODE_ID: 14,
            const.ATTR_INSTANCE: 2,
        })
        self.hass.block_till_done()

        assert not self.zwave_network.manager.pressButton.called
        assert not self.zwave_network.manager.releaseButton.called

        self.hass.services.call('zwave', 'reset_node_meters', {
            const.ATTR_NODE_ID: 14,
        })
        self.hass.block_till_done()

        assert self.zwave_network.manager.pressButton.called
        value_id, = self.zwave_network.manager.pressButton.mock_calls.pop(0)[1]
        assert value_id == reset_value.value_id
        assert self.zwave_network.manager.releaseButton.called
        value_id, = (
            self.zwave_network.manager.releaseButton.mock_calls.pop(0)[1])
        assert value_id == reset_value.value_id
コード例 #32
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
コード例 #33
0
ファイル: test_fan.py プロジェクト: nickovs/home-assistant
def test_fan_turn_off(mock_openzwave):
    """Test turning off a dimmable zwave fan."""
    node = MockNode()
    value = MockValue(data=46, node=node)
    values = MockEntityValues(primary=value)
    device = fan.get_device(node=node, values=values, node_config={})

    device.turn_off()

    assert node.set_dimmer.called
    value_id, brightness = node.set_dimmer.mock_calls[0][1]
    assert value_id == value.value_id
    assert brightness == 0
コード例 #34
0
ファイル: test_init.py プロジェクト: wigginzz/home-assistant
def test_power_schemes(hass, mock_openzwave):
    """Test power attribute."""
    mock_receivers = []

    def mock_connect(receiver, signal, *args, **kwargs):
        if signal == MockNetwork.SIGNAL_VALUE_ADDED:
            mock_receivers.append(receiver)

    with patch('pydispatch.dispatcher.connect', new=mock_connect):
        yield from async_setup_component(hass, 'zwave', {'zwave': {}})

    assert len(mock_receivers) == 1

    node = MockNode(node_id=11, generic=const.GENERIC_TYPE_SWITCH_BINARY)
    switch = MockValue(
        data=True, node=node, index=12, instance=13,
        command_class=const.COMMAND_CLASS_SWITCH_BINARY,
        genre=const.GENRE_USER, type=const.TYPE_BOOL)
    hass.async_add_job(mock_receivers[0], node, switch)

    yield from hass.async_block_till_done()

    assert hass.states.get('switch.mock_node_mock_value').state == 'on'
    assert 'power_consumption' not in hass.states.get(
        'switch.mock_node_mock_value').attributes

    def mock_update(self):
        self.hass.add_job(self.async_update_ha_state)

    with patch.object(zwave.node_entity.ZWaveBaseEntity,
                      'maybe_schedule_update', new=mock_update):
        power = MockValue(
            data=23.5, node=node, index=const.INDEX_SENSOR_MULTILEVEL_POWER,
            instance=13, command_class=const.COMMAND_CLASS_SENSOR_MULTILEVEL)
        hass.async_add_job(mock_receivers[0], node, power)
        yield from hass.async_block_till_done()

    assert hass.states.get('switch.mock_node_mock_value').attributes[
        'power_consumption'] == 23.5
コード例 #35
0
def test_dimmer_refresh_value(mock_openzwave):
    """Test value changed for dimmer lights."""
    node = MockNode()
    value = MockValue(data=0, node=node)
    values = MockLightValues(primary=value)
    device = light.get_device(node=node,
                              values=values,
                              node_config={
                                  zwave.CONF_REFRESH_VALUE: True,
                                  zwave.CONF_REFRESH_DELAY: 5,
                              })

    assert not device.is_on

    with patch.object(light, 'Timer', MagicMock()) as mock_timer:
        value.data = 46
        value_changed(value)

        assert not device.is_on
        assert mock_timer.called
        assert len(mock_timer.mock_calls) == 2
        timeout, callback = mock_timer.mock_calls[0][1][:2]
        assert timeout == 5
        assert mock_timer().start.called
        assert len(mock_timer().start.mock_calls) == 1

        with patch.object(light, 'Timer', MagicMock()) as mock_timer_2:
            value_changed(value)
            assert not device.is_on
            assert mock_timer().cancel.called
            assert len(mock_timer_2.mock_calls) == 2
            timeout, callback = mock_timer_2.mock_calls[0][1][:2]
            assert timeout == 5
            assert mock_timer_2().start.called
            assert len(mock_timer_2().start.mock_calls) == 1

            callback()
            assert device.is_on
            assert device.brightness == 118
コード例 #36
0
def test_roller_commands(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={})

    device.set_cover_position(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
コード例 #37
0
async def test_lock_set_usercode_service(hass, mock_openzwave):
    """Test the zwave lock set_usercode service."""
    mock_network = hass.data[zwave.zwave.DATA_NETWORK] = MagicMock()

    node = MockNode(node_id=12)
    value0 = MockValue(data='          ', node=node, index=0)
    value1 = MockValue(data='          ', node=node, index=1)

    node.get_values.return_value = {
        value0.value_id: value0,
        value1.value_id: value1,
    }

    mock_network.nodes = {node.node_id: node}

    await setup_ozw(hass, mock_openzwave)
    await hass.async_block_till_done()

    await hass.services.async_call(
        zwave.DOMAIN, zwave.SERVICE_SET_USERCODE, {
            const.ATTR_NODE_ID: node.node_id,
            zwave.ATTR_USERCODE: '1234',
            zwave.ATTR_CODE_SLOT: 1,
        })
    await hass.async_block_till_done()

    assert value1.data == '1234'

    mock_network.nodes = {node.node_id: node}
    await hass.services.async_call(
        zwave.DOMAIN, zwave.SERVICE_SET_USERCODE, {
            const.ATTR_NODE_ID: node.node_id,
            zwave.ATTR_USERCODE: '123',
            zwave.ATTR_CODE_SLOT: 1,
        })
    await hass.async_block_till_done()

    assert value1.data == '1234'
コード例 #38
0
def test_get_device_detects_multilevelsensor(mock_openzwave):
    """Test get_device returns a Z-Wave multilevel sensor."""
    node = MockNode(
        command_classes=[
            const.COMMAND_CLASS_SENSOR_MULTILEVEL,
            const.COMMAND_CLASS_METER,
        ]
    )
    value = MockValue(data=0, node=node)
    values = MockEntityValues(primary=value)

    device = sensor.get_device(node=node, values=values, node_config={})
    assert isinstance(device, sensor.ZWaveMultilevelSensor)
    assert device.force_update
コード例 #39
0
ファイル: test_light.py プロジェクト: zt17521/home-assistant
def test_disable_white_if_set_color(mock_openzwave):
    """
    Test that _white is set to 0 if turn_on with ATTR_HS_COLOR.

    See Issue #13930 - many RGBW ZWave bulbs will only activate the RGB LED to
    produce color if _white is set to zero.
    """
    node = MockNode(command_classes=[const.COMMAND_CLASS_SWITCH_COLOR])
    value = MockValue(data=0, node=node)
    color = MockValue(data="#0000000000", node=node)
    # Supports RGB only
    color_channels = MockValue(data=0x1C, node=node)
    values = MockLightValues(primary=value, color=color, color_channels=color_channels)
    device = light.get_device(node=node, values=values, node_config={})
    device._white = 234

    assert color.data == "#0000000000"
    assert device.white_value == 234

    device.turn_on(**{ATTR_HS_COLOR: (30, 50)})

    assert device.white_value == 0
    assert color.data == "#ffbf7f0000"
コード例 #40
0
def test_get_usercodes(hass, client):
    """Test getting usercodes on node."""
    network = hass.data[DATA_NETWORK] = MagicMock()
    node = MockNode(node_id=18,
                    command_classes=[const.COMMAND_CLASS_USER_CODE])
    value = MockValue(
        index=0,
        command_class=const.COMMAND_CLASS_USER_CODE)
    value.genre = const.GENRE_USER
    value.label = 'label'
    value.data = '1234'
    node.values = {0: value}
    network.nodes = {18: node}
    node.get_values.return_value = node.values

    resp = yield from client.get('/api/zwave/usercodes/18')

    assert resp.status == 200
    result = yield from resp.json()

    assert result == {'0': {'code': '1234',
                            'label': 'label',
                            'length': 4}}
コード例 #41
0
ファイル: test_zwave.py プロジェクト: nunofgs/home-assistant
def test_ct_value_changed(mock_openzwave):
    """Test value changed for zw098 lights."""
    node = MockNode(manufacturer_id='0086', product_id='0062',
                    command_classes=[const.COMMAND_CLASS_SWITCH_COLOR])
    value = MockValue(data=0, node=node)
    color = MockValue(data=b'#0000000000', node=node)
    # Suppoorts RGB, Cold White
    color_channels = MockValue(data=0x1f, node=node)
    values = MockLightValues(primary=value, color=color,
                             color_channels=color_channels)
    device = zwave.get_device(node=node, values=values, node_config={})

    assert device.color_temp == zwave.TEMP_MID_HASS

    color.data = b'#000000ff00'
    value_changed(color)

    assert device.color_temp == zwave.TEMP_WARM_HASS

    color.data = b'#00000000ff'
    value_changed(color)

    assert device.color_temp == zwave.TEMP_COLD_HASS
コード例 #42
0
ファイル: test_cover.py プロジェクト: nickovs/home-assistant
def test_barrier_garage_commands(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 = cover.get_device(hass=hass, node=node, values=values, node_config={})

    assert value.data == "Closed"
    device.open_cover()
    assert value.data == "Opened"
    device.close_cover()
    assert value.data == "Closed"
コード例 #43
0
ファイル: test_cover.py プロジェクト: nickovs/home-assistant
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 = cover.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
コード例 #44
0
def test_roller_no_position_workaround(hass, mock_openzwave):
    """Test position changed."""
    hass.data[zwave.zwave.DATA_NETWORK] = MagicMock()
    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(hass=hass,
                              node=node,
                              values=values,
                              node_config={})

    assert device.current_cover_position is None
コード例 #45
0
def test_get_device_detects_rollershutter(hass, mock_openzwave):
    """Test device returns rollershutter."""
    hass.data[zwave.zwave.DATA_NETWORK] = MagicMock()
    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(hass=hass,
                              node=node,
                              values=values,
                              node_config={})
    assert isinstance(device, zwave.ZwaveRollershutter)
コード例 #46
0
def test_switch_refresh_on_update(mock_counter, mock_openzwave):
    """Test value changed for refresh on update Z-Wave switch."""
    mock_counter.return_value = 10
    node = MockNode(manufacturer_id="013c", product_type="0001", product_id="0005")
    value = MockValue(data=False, node=node, instance=1)
    values = MockEntityValues(primary=value)
    device = switch.get_device(node=node, values=values, node_config={})

    assert not device.is_on

    mock_counter.return_value = 15
    value.data = True
    value_changed(value)

    assert device.is_on
    assert not node.request_state.called

    mock_counter.return_value = 45
    value.data = False
    value_changed(value)

    assert not device.is_on
    assert node.request_state.called
コード例 #47
0
ファイル: test_zwave.py プロジェクト: MoshonkaKita/Golovastik
def test_zw098_set_color_temp(mock_openzwave):
    """Test setting zwave light color."""
    node = MockNode(manufacturer_id='0086',
                    product_id='0062',
                    command_classes=[const.COMMAND_CLASS_SWITCH_COLOR])
    value = MockValue(data=0, node=node)
    color = MockValue(data='#0000000000', node=node)
    # Supports RGB, warm white, cold white
    color_channels = MockValue(data=0x1f, node=node)
    values = MockLightValues(primary=value,
                             color=color,
                             color_channels=color_channels)
    device = zwave.get_device(node=node, values=values, node_config={})

    assert color.data == '#0000000000'

    device.turn_on(**{ATTR_COLOR_TEMP: 200})

    assert color.data == '#00000000ff'

    device.turn_on(**{ATTR_COLOR_TEMP: 400})

    assert color.data == '#000000ff00'
コード例 #48
0
ファイル: test_zwave.py プロジェクト: nunofgs/home-assistant
def test_dimmer_refresh_value(mock_openzwave):
    """Test value changed for dimmer lights."""
    node = MockNode()
    value = MockValue(data=0, node=node)
    values = MockLightValues(primary=value)
    device = zwave.get_device(node=node, values=values, node_config={
        homeassistant.components.zwave.CONF_REFRESH_VALUE: True,
        homeassistant.components.zwave.CONF_REFRESH_DELAY: 5,
    })

    assert not device.is_on

    with patch.object(zwave, 'Timer', MagicMock()) as mock_timer:
        value.data = 46
        value_changed(value)

        assert not device.is_on
        assert mock_timer.called
        assert len(mock_timer.mock_calls) == 2
        timeout, callback = mock_timer.mock_calls[0][1][:2]
        assert timeout == 5
        assert mock_timer().start.called
        assert len(mock_timer().start.mock_calls) == 1

        with patch.object(zwave, 'Timer', MagicMock()) as mock_timer_2:
            value_changed(value)
            assert not device.is_on
            assert mock_timer().cancel.called
            assert len(mock_timer_2.mock_calls) == 2
            timeout, callback = mock_timer_2.mock_calls[0][1][:2]
            assert timeout == 5
            assert mock_timer_2().start.called
            assert len(mock_timer_2().start.mock_calls) == 1

            callback()
            assert device.is_on
            assert device.brightness == 118
コード例 #49
0
def test_get_device_detects_garagedoor_barrier(hass, mock_openzwave):
    """Test device returns garage door."""
    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 isinstance(device, zwave.ZwaveGarageDoorBarrier)
    assert device.device_class == "garage"
    assert device.supported_features == SUPPORT_OPEN | SUPPORT_CLOSE
コード例 #50
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
コード例 #51
0
async def test_get_protection_values(hass, client):
    """Test getting protection values on node."""
    network = hass.data[DATA_NETWORK] = MagicMock()
    node = MockNode(node_id=18,
                    command_classes=[const.COMMAND_CLASS_PROTECTION])
    value = MockValue(value_id=123456,
                      index=0,
                      instance=1,
                      command_class=const.COMMAND_CLASS_PROTECTION)
    value.label = 'Protection Test'
    value.data_items = [
        'Unprotected', 'Protection by Sequence', 'No Operation Possible'
    ]
    value.data = 'Unprotected'
    network.nodes = {18: node}
    node.value = value

    node.get_protection_item.return_value = "Unprotected"
    node.get_protection_items.return_value = value.data_items
    node.get_protections.return_value = {value.value_id: 'Object'}

    resp = await client.get('/api/zwave/protection/18')

    assert resp.status == 200
    result = await resp.json()
    assert node.get_protections.called
    assert node.get_protection_item.called
    assert node.get_protection_items.called
    assert result == {
        'value_id':
        '123456',
        'selected':
        'Unprotected',
        'options':
        ['Unprotected', 'Protection by Sequence', 'No Operation Possible']
    }
コード例 #52
0
def test_device_entity(hass, mock_openzwave):
    """Test device entity base class."""
    node = MockNode(node_id='10', name='Mock Node')
    value = MockValue(data=False,
                      node=node,
                      instance=2,
                      object_id='11',
                      label='Sensor',
                      command_class=const.COMMAND_CLASS_SENSOR_BINARY)
    power_value = MockValue(data=50.123456,
                            node=node,
                            precision=3,
                            command_class=const.COMMAND_CLASS_METER)
    values = MockEntityValues(primary=value, power=power_value)
    device = zwave.ZWaveDeviceEntity(values, 'zwave')
    device.hass = hass
    device.value_added()
    device.update_properties()
    yield from hass.async_block_till_done()

    assert not device.should_poll
    assert device.unique_id == "ZWAVE-10-11"
    assert device.name == 'Mock Node Sensor'
    assert device.device_state_attributes[zwave.ATTR_POWER] == 50.123
コード例 #53
0
ファイル: test_zwave.py プロジェクト: azogue/home-assistant
def test_switch_refresh_on_update(mock_counter, mock_openzwave):
    """Test value changed for refresh on update Z-Wave switch."""
    mock_counter.return_value = 10
    node = MockNode(manufacturer_id='013c', product_type='0001',
                    product_id='0005')
    value = MockValue(data=False, node=node)
    values = MockEntityValues(primary=value)
    device = zwave.get_device(node=node, values=values, node_config={})

    assert not device.is_on

    mock_counter.return_value = 15
    value.data = True
    value_changed(value)

    assert device.is_on
    assert not node.request_state.called

    mock_counter.return_value = 45
    value.data = False
    value_changed(value)

    assert not device.is_on
    assert node.request_state.called
コード例 #54
0
def test_get_usercodes_no_genreuser(hass, test_client):
    """Test getting usercodes on node missing genre user."""
    app = mock_http_component_app(hass)
    ZWaveUserCodeView().register(app.router)

    network = hass.data[ZWAVE_NETWORK] = MagicMock()
    node = MockNode(node_id=18,
                    command_classes=[const.COMMAND_CLASS_USER_CODE])
    value = MockValue(index=0, command_class=const.COMMAND_CLASS_USER_CODE)
    value.genre = const.GENRE_SYSTEM
    value.label = 'label'
    value.data = '1234'
    node.values = {0: value}
    network.nodes = {18: node}
    node.get_values.return_value = node.values

    client = yield from test_client(app)

    resp = yield from client.get('/api/zwave/usercodes/18')

    assert resp.status == 200
    result = yield from resp.json()

    assert result == {}
コード例 #55
0
def test_get_device_detects_battery_sensor(mock_openzwave):
    """Test get_device returns a Z-Wave battery sensor."""

    node = MockNode(command_classes=[const.COMMAND_CLASS_BATTERY])
    value = MockValue(
        data=0,
        node=node,
        type=const.TYPE_DECIMAL,
        command_class=const.COMMAND_CLASS_BATTERY,
    )
    values = MockEntityValues(primary=value)

    device = sensor.get_device(node=node, values=values, node_config={})
    assert isinstance(device, sensor.ZWaveBatterySensor)
    assert device.device_class == homeassistant.const.DEVICE_CLASS_BATTERY
コード例 #56
0
async def test_lock_get_usercode_service(hass, mock_openzwave):
    """Test the zwave lock get_usercode service."""
    mock_network = hass.data[const.DATA_NETWORK] = MagicMock()
    node = MockNode(node_id=12)
    value0 = MockValue(data=None, node=node, index=0)
    value1 = MockValue(data="1234", node=node, index=1)

    node.get_values.return_value = {value0.value_id: value0, value1.value_id: value1}

    await setup_ozw(hass, mock_openzwave)
    await hass.async_block_till_done()

    with patch.object(lock, "_LOGGER") as mock_logger:
        mock_network.nodes = {node.node_id: node}
        await hass.services.async_call(
            lock.DOMAIN,
            lock.SERVICE_GET_USERCODE,
            {const.ATTR_NODE_ID: node.node_id, lock.ATTR_CODE_SLOT: 1},
        )
        await hass.async_block_till_done()
        # This service only seems to write to the log
        assert mock_logger.info.called
        assert len(mock_logger.info.mock_calls) == 1
        assert mock_logger.info.mock_calls[0][1][2] == "1234"
コード例 #57
0
ファイル: test_init.py プロジェクト: wigginzz/home-assistant
    def test_refresh_entity(self):
        """Test zwave refresh_entity service."""
        node = MockNode()
        value = MockValue(data=False, node=node,
                          command_class=const.COMMAND_CLASS_SENSOR_BINARY)
        power_value = MockValue(data=50, node=node,
                                command_class=const.COMMAND_CLASS_METER)
        values = MockEntityValues(primary=value, power=power_value)
        device = get_device(node=node, values=values, node_config={})
        device.hass = self.hass
        device.entity_id = 'binary_sensor.mock_entity_id'
        self.hass.add_job(device.async_added_to_hass())
        self.hass.block_till_done()

        self.hass.services.call('zwave', 'refresh_entity', {
            ATTR_ENTITY_ID: 'binary_sensor.mock_entity_id',
        })
        self.hass.block_till_done()

        assert node.refresh_value.called
        assert len(node.refresh_value.mock_calls) == 2
        self.assertEqual(sorted([node.refresh_value.mock_calls[0][1][0],
                                 node.refresh_value.mock_calls[1][1][0]]),
                         sorted([value.value_id, power_value.value_id]))