• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python zwave.MockNode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tests.mock.zwave.MockNode的典型用法代码示例。如果您正苦于以下问题:Python MockNode类的具体用法?Python MockNode怎么用?Python MockNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了MockNode类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_get_usercodes_no_genreuser

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 == {}
开发者ID:tedstriker,项目名称:home-assistant,代码行数:26,代码来源:test_api.py


示例2: test_get_groups

def test_get_groups(hass, test_client):
    """Test getting groupdata on node."""
    app = mock_http_component_app(hass)
    ZWaveNodeGroupView().register(app.router)

    network = hass.data[DATA_NETWORK] = MagicMock()
    node = MockNode(node_id=2)
    node.groups.associations = 'assoc'
    node.groups.associations_instances = 'inst'
    node.groups.label = 'the label'
    node.groups.max_associations = 'max'
    node.groups = {1: node.groups}
    network.nodes = {2: node}

    client = yield from test_client(app)

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

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

    assert result == {
        '1': {
            'association_instances': 'inst',
            'associations': 'assoc',
            'label': 'the label',
            'max_associations': 'max'
        }
    }
开发者ID:tedstriker,项目名称:home-assistant,代码行数:29,代码来源:test_api.py


示例3: test_get_protection_values

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']
    }
开发者ID:Martwall,项目名称:home-assistant,代码行数:34,代码来源:test_zwave.py


示例4: test_get_config

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'}}
开发者ID:tedstriker,项目名称:home-assistant,代码行数:35,代码来源:test_api.py


示例5: test_remove_association

    def test_remove_association(self):
        """Test zwave change_association service."""
        ZWaveGroup = self.mock_openzwave.group.ZWaveGroup
        group = MagicMock()
        ZWaveGroup.return_value = group

        value = MockValue(
            index=12,
            command_class=const.COMMAND_CLASS_WAKE_UP,
        )
        node = MockNode(node_id=14)
        node.values = {12: value}
        node.get_values.return_value = node.values
        self.zwave_network.nodes = {14: node}

        self.hass.services.call('zwave', 'change_association', {
            const.ATTR_ASSOCIATION: 'remove',
            const.ATTR_NODE_ID: 14,
            const.ATTR_TARGET_NODE_ID: 24,
            const.ATTR_GROUP: 3,
            const.ATTR_INSTANCE: 5,
        })
        self.hass.block_till_done()

        assert ZWaveGroup.called
        assert len(ZWaveGroup.mock_calls) == 2
        assert ZWaveGroup.mock_calls[0][1][0] == 3
        assert ZWaveGroup.mock_calls[0][1][2] == 14
        assert group.remove_association.called
        assert len(group.remove_association.mock_calls) == 1
        assert group.remove_association.mock_calls[0][1][0] == 24
        assert group.remove_association.mock_calls[0][1][1] == 5
开发者ID:keatontaylor,项目名称:home-assistant,代码行数:32,代码来源:test_init.py


示例6: test_print_config_parameter

    def test_print_config_parameter(self):
        """Test zwave print_config_parameter service."""
        value1 = MockValue(
            index=12,
            command_class=const.COMMAND_CLASS_CONFIGURATION,
            data=1234,
        )
        value2 = MockValue(
            index=13,
            command_class=const.COMMAND_CLASS_CONFIGURATION,
            data=2345,
        )
        node = MockNode(node_id=14)
        node.values = {12: value1, 13: value2}
        self.zwave_network.nodes = {14: node}

        with patch.object(zwave, '_LOGGER') as mock_logger:
            self.hass.services.call('zwave', 'print_config_parameter', {
                const.ATTR_NODE_ID: 14,
                const.ATTR_CONFIG_PARAMETER: 13,
            })
            self.hass.block_till_done()

            assert mock_logger.info.called
            assert len(mock_logger.info.mock_calls) == 1
            assert mock_logger.info.mock_calls[0][1][1] == 13
            assert mock_logger.info.mock_calls[0][1][2] == 14
            assert mock_logger.info.mock_calls[0][1][3] == 2345
开发者ID:keatontaylor,项目名称:home-assistant,代码行数:28,代码来源:test_init.py


示例7: test_set_wakeup

    def test_set_wakeup(self):
        """Test zwave set_wakeup service."""
        value = MockValue(
            index=12,
            command_class=const.COMMAND_CLASS_WAKE_UP,
        )
        node = MockNode(node_id=14)
        node.values = {12: value}
        node.get_values.return_value = node.values
        self.zwave_network.nodes = {14: node}

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

        assert value.data == 15

        node.can_wake_up_value = False
        self.hass.services.call('zwave', 'set_wakeup', {
            const.ATTR_NODE_ID: 14,
            const.ATTR_CONFIG_VALUE: 20,
        })
        self.hass.block_till_done()

        assert value.data == 15
开发者ID:keatontaylor,项目名称:home-assistant,代码行数:27,代码来源:test_init.py


示例8: test_set_protection_value_nonexisting_node

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'}
开发者ID:Martwall,项目名称:home-assistant,代码行数:26,代码来源:test_zwave.py


示例9: test_dimmer_turn_on

def test_dimmer_turn_on(mock_openzwave):
    """Test turning on a dimmable Z-Wave light."""
    node = MockNode()
    value = MockValue(data=0, node=node)
    values = MockLightValues(primary=value)
    device = zwave.get_device(node=node, values=values, node_config={})

    device.turn_on()

    assert node.set_dimmer.called
    value_id, brightness = node.set_dimmer.mock_calls[0][1]
    assert value_id == value.value_id
    assert brightness == 255

    node.reset_mock()

    device.turn_on(**{ATTR_BRIGHTNESS: 120})

    assert node.set_dimmer.called
    value_id, brightness = node.set_dimmer.mock_calls[0][1]

    assert value_id == value.value_id
    assert brightness == 46  # int(120 / 255 * 99)

    with patch.object(zwave, '_LOGGER', MagicMock()) as mock_logger:
        device.turn_on(**{ATTR_TRANSITION: 35})
        assert mock_logger.debug.called
        assert node.set_dimmer.called
        msg, entity_id = mock_logger.debug.mock_calls[0][1]
        assert entity_id == device.entity_id
开发者ID:azogue,项目名称:home-assistant,代码行数:30,代码来源:test_zwave.py


示例10: test_get_protection_values_nonexisting_node

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'}
开发者ID:Martwall,项目名称:home-assistant,代码行数:25,代码来源:test_zwave.py


示例11: test_fan_turn_on

def test_fan_turn_on(mock_openzwave):
    """Test turning on a zwave fan."""
    node = MockNode()
    value = MockValue(data=0, node=node)
    values = MockEntityValues(primary=value)
    device = zwave.get_device(node=node, values=values, node_config={})

    device.turn_on()

    assert node.set_dimmer.called
    value_id, brightness = node.set_dimmer.mock_calls[0][1]
    assert value_id == value.value_id
    assert brightness == 255

    node.reset_mock()

    device.turn_on(speed=SPEED_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

    node.reset_mock()

    device.turn_on(speed=SPEED_LOW)

    assert node.set_dimmer.called
    value_id, brightness = node.set_dimmer.mock_calls[0][1]

    assert value_id == value.value_id
    assert brightness == 1

    node.reset_mock()

    device.turn_on(speed=SPEED_MEDIUM)

    assert node.set_dimmer.called
    value_id, brightness = node.set_dimmer.mock_calls[0][1]

    assert value_id == value.value_id
    assert brightness == 50

    node.reset_mock()

    device.turn_on(speed=SPEED_HIGH)

    assert node.set_dimmer.called
    value_id, brightness = node.set_dimmer.mock_calls[0][1]

    assert value_id == value.value_id
    assert brightness == 99
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:53,代码来源:test_zwave.py


示例12: test_rename_value

    def test_rename_value(self):
        """Test zwave rename_value service."""
        node = MockNode(node_id=14)
        value = MockValue(index=12, value_id=123456, label="Old Label")
        node.values = {123456: value}
        self.zwave_network.nodes = {11: node}

        assert value.label == "Old Label"
        self.hass.services.call('zwave', 'rename_value', {
            const.ATTR_NODE_ID: 11,
            const.ATTR_VALUE_ID: 123456,
            const.ATTR_NAME: "New Label",
        })
        self.hass.block_till_done()

        assert value.label == "New Label"
开发者ID:keatontaylor,项目名称:home-assistant,代码行数:16,代码来源:test_init.py


示例13: test_set_poll_intensity_disable

    def test_set_poll_intensity_disable(self):
        """Test zwave set_poll_intensity service, successful disable."""
        node = MockNode(node_id=14)
        value = MockValue(index=12, value_id=123456, poll_intensity=4)
        node.values = {123456: value}
        self.zwave_network.nodes = {11: node}

        assert value.poll_intensity == 4
        self.hass.services.call('zwave', 'set_poll_intensity', {
            const.ATTR_NODE_ID: 11,
            const.ATTR_VALUE_ID: 123456,
            const.ATTR_POLL_INTENSITY: 0,
        })
        self.hass.block_till_done()

        disable_poll = value.disable_poll
        assert value.disable_poll.called
        assert len(disable_poll.mock_calls) == 2
开发者ID:keatontaylor,项目名称:home-assistant,代码行数:18,代码来源:test_init.py


示例14: test_get_protection_values_without_protectionclass

async def test_get_protection_values_without_protectionclass(hass, client):
    """Test getting protection values on node without protectionclass."""
    network = hass.data[DATA_NETWORK] = MagicMock()
    node = MockNode(node_id=18)
    value = MockValue(
        value_id=123456,
        index=0,
        instance=1)
    network.nodes = {18: node}
    node.value = value

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

    assert resp.status == 200
    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 == {}
开发者ID:Martwall,项目名称:home-assistant,代码行数:19,代码来源:test_zwave.py


示例15: test_set_poll_intensity_enable_failed

    def test_set_poll_intensity_enable_failed(self):
        """Test zwave set_poll_intensity service, failed set."""
        node = MockNode(node_id=14)
        value = MockValue(index=12, value_id=123456, poll_intensity=0)
        value.enable_poll.return_value = False
        node.values = {123456: value}
        self.zwave_network.nodes = {11: node}

        assert value.poll_intensity == 0
        self.hass.services.call('zwave', 'set_poll_intensity', {
            const.ATTR_NODE_ID: 11,
            const.ATTR_VALUE_ID: 123456,
            const.ATTR_POLL_INTENSITY: 4,
        })
        self.hass.block_till_done()

        enable_poll = value.enable_poll
        assert value.enable_poll.called
        assert len(enable_poll.mock_calls) == 1
开发者ID:keatontaylor,项目名称:home-assistant,代码行数:19,代码来源:test_init.py


示例16: test_track_message_workaround

def test_track_message_workaround(mock_openzwave):
    """Test value changed for Z-Wave lock by alarm-clearing workaround."""
    node = MockNode(manufacturer_id='003B', product_id='5044',
                    stats={'lastReceivedMessage': [0] * 6})
    values = MockEntityValues(
        primary=MockValue(data=True, node=node),
        access_control=None,
        alarm_type=None,
        alarm_level=None,
    )

    # Here we simulate an RF lock. The first zwave.get_device will call
    # update properties, simulating the first DoorLock report. We then trigger
    # a change, simulating the openzwave automatic refreshing behavior (which
    # is enabled for at least the lock that needs this workaround)
    node.stats['lastReceivedMessage'][5] = const.COMMAND_CLASS_DOOR_LOCK
    device = zwave.get_device(node=node, values=values)
    value_changed(values.primary)
    assert device.is_locked
    assert device.device_state_attributes[zwave.ATTR_NOTIFICATION] == 'RF Lock'

    # Simulate a keypad unlock. We trigger a value_changed() which simulates
    # the Alarm notification received from the lock. Then, we trigger
    # value_changed() to simulate the automatic refreshing behavior.
    values.access_control = MockValue(data=6, node=node)
    values.alarm_type = MockValue(data=19, node=node)
    values.alarm_level = MockValue(data=3, node=node)
    node.stats['lastReceivedMessage'][5] = const.COMMAND_CLASS_ALARM
    value_changed(values.access_control)
    node.stats['lastReceivedMessage'][5] = const.COMMAND_CLASS_DOOR_LOCK
    values.primary.data = False
    value_changed(values.primary)
    assert not device.is_locked
    assert device.device_state_attributes[zwave.ATTR_LOCK_STATUS] == \
        'Unlocked with Keypad by user 3'

    # Again, simulate an RF lock.
    device.lock()
    node.stats['lastReceivedMessage'][5] = const.COMMAND_CLASS_DOOR_LOCK
    value_changed(values.primary)
    assert device.is_locked
    assert device.device_state_attributes[zwave.ATTR_NOTIFICATION] == 'RF Lock'
开发者ID:Martwall,项目名称:home-assistant,代码行数:42,代码来源:test_zwave.py


示例17: test_set_protection_value_missing_class

async def test_set_protection_value_missing_class(hass, client):
    """Test setting protection value on node without protectionclass."""
    network = hass.data[DATA_NETWORK] = MagicMock()
    node = MockNode(node_id=17)
    value = MockValue(
        value_id=123456,
        index=0,
        instance=1)
    network.nodes = {17: node}
    node.value = value
    node.set_protection.return_value = False

    resp = await client.post(
        '/api/zwave/protection/17', 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': 'No protection commandclass on this node'}
开发者ID:Martwall,项目名称:home-assistant,代码行数:20,代码来源:test_zwave.py


示例18: test_switch_turn_on_and_off

def test_switch_turn_on_and_off(mock_openzwave):
    """Test turning on a Z-Wave switch."""
    node = MockNode()
    value = MockValue(data=0, node=node)
    values = MockEntityValues(primary=value)
    device = zwave.get_device(node=node, values=values, node_config={})

    device.turn_on()

    assert node.set_switch.called
    value_id, state = node.set_switch.mock_calls[0][1]
    assert value_id == value.value_id
    assert state is True
    node.reset_mock()

    device.turn_off()

    assert node.set_switch.called
    value_id, state = node.set_switch.mock_calls[0][1]
    assert value_id == value.value_id
    assert state is False
开发者ID:azogue,项目名称:home-assistant,代码行数:21,代码来源:test_zwave.py


示例19: test_dimmer_turn_on

def test_dimmer_turn_on(mock_openzwave):
    """Test turning on a dimmable Z-Wave light."""
    node = MockNode()
    value = MockValue(data=0, node=node)
    device = zwave.get_device(node, value, {})

    device.turn_on()

    assert node.set_dimmer.called
    value_id, brightness = node.set_dimmer.mock_calls[0][1]
    assert value_id == value.value_id
    assert brightness == 255

    node.reset_mock()

    device.turn_on(**{ATTR_BRIGHTNESS: 120})

    assert node.set_dimmer.called
    value_id, brightness = node.set_dimmer.mock_calls[0][1]

    assert value_id == value.value_id
    assert brightness == 46  # int(120 / 255 * 99)
开发者ID:zebpalmer,项目名称:home-assistant,代码行数:22,代码来源:test_zwave.py


示例20: test_reset_node_meters

    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
开发者ID:keatontaylor,项目名称:home-assistant,代码行数:39,代码来源:test_init.py



注:本文中的tests.mock.zwave.MockNode类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python zwave.MockValue类代码示例发布时间:2022-05-27
下一篇:
Python zwave.value_changed函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap