Exemplo n.º 1
0
    def test_entity_workaround_component(self, discovery, get_platform):
        """Test ignore workaround."""
        self.node.manufacturer_id = '010f'
        self.node.product_type = '0b00'
        self.primary.command_class = const.COMMAND_CLASS_SENSOR_ALARM
        self.entity_id = '{}.{}'.format('binary_sensor',
                                        zwave.object_id(self.primary))
        self.device_config = {self.entity_id: {}}

        self.mock_schema = {
            const.DISC_COMPONENT: 'mock_component',
            const.DISC_VALUES: {
                const.DISC_PRIMARY: {
                    const.DISC_COMMAND_CLASS:
                    [const.COMMAND_CLASS_SWITCH_BINARY],
                }
            }
        }

        values = zwave.ZWaveDeviceEntityValues(
            hass=self.hass,
            schema=self.mock_schema,
            primary_value=self.primary,
            zwave_config=self.zwave_config,
            device_config=self.device_config,
        )
        values._check_entity_ready()
        self.hass.block_till_done()

        assert discovery.async_load_platform.called
        # Second call is to async yield from
        assert len(discovery.async_load_platform.mock_calls) == 2
        args = discovery.async_load_platform.mock_calls[0][1]
        assert args[1] == 'binary_sensor'
Exemplo n.º 2
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Find and add Z-Wave lights."""
    if discovery_info is None or zwave.NETWORK is None:
        return
    node = zwave.NETWORK.nodes[discovery_info[zwave.const.ATTR_NODE_ID]]
    value = node.values[discovery_info[zwave.const.ATTR_VALUE_ID]]
    customize = hass.data['zwave_customize']
    name = '{}.{}'.format(DOMAIN, zwave.object_id(value))
    node_config = customize.get(name, {})
    refresh = node_config.get(zwave.CONF_REFRESH_VALUE)
    delay = node_config.get(zwave.CONF_REFRESH_DELAY)
    _LOGGER.debug(
        'customize=%s name=%s node_config=%s CONF_REFRESH_VALUE=%s'
        ' CONF_REFRESH_DELAY=%s', customize, name, node_config, refresh, delay)
    if value.command_class != zwave.const.COMMAND_CLASS_SWITCH_MULTILEVEL:
        return
    if value.type != zwave.const.TYPE_BYTE:
        return
    if value.genre != zwave.const.GENRE_USER:
        return

    value.set_change_verified(False)

    if node.has_command_class(zwave.const.COMMAND_CLASS_SWITCH_COLOR):
        add_devices([ZwaveColorLight(value, refresh, delay)])
    else:
        add_devices([ZwaveDimmer(value, refresh, delay)])
Exemplo n.º 3
0
    def test_entity_workaround_component(self, discovery, get_platform):
        """Test ignore workaround."""
        self.node.manufacturer_id = '010f'
        self.node.product_type = '0b00'
        self.primary.command_class = const.COMMAND_CLASS_SENSOR_ALARM
        self.entity_id = '{}.{}'.format('binary_sensor',
                                        zwave.object_id(self.primary))
        self.device_config = {self.entity_id: {}}

        self.mock_schema = {
            const.DISC_COMPONENT: 'mock_component',
            const.DISC_VALUES: {
                const.DISC_PRIMARY: {
                    const.DISC_COMMAND_CLASS: [
                        const.COMMAND_CLASS_SWITCH_BINARY],
                }}}

        values = zwave.ZWaveDeviceEntityValues(
            hass=self.hass,
            schema=self.mock_schema,
            primary_value=self.primary,
            zwave_config=self.zwave_config,
            device_config=self.device_config,
        )
        values._check_entity_ready()
        self.hass.block_till_done()

        assert discovery.async_load_platform.called
        # Second call is to async yield from
        assert len(discovery.async_load_platform.mock_calls) == 2
        args = discovery.async_load_platform.mock_calls[0][1]
        assert args[1] == 'binary_sensor'
Exemplo n.º 4
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Find and add Z-Wave lights."""
    if discovery_info is None or zwave.NETWORK is None:
        return
    node = zwave.NETWORK.nodes[discovery_info[zwave.const.ATTR_NODE_ID]]
    value = node.values[discovery_info[zwave.const.ATTR_VALUE_ID]]
    name = '{}.{}'.format(DOMAIN, zwave.object_id(value))
    node_config = hass.data[zwave.DATA_DEVICE_CONFIG].get(name)
    refresh = node_config.get(zwave.CONF_REFRESH_VALUE)
    delay = node_config.get(zwave.CONF_REFRESH_DELAY)
    _LOGGER.debug('name=%s node_config=%s CONF_REFRESH_VALUE=%s'
                  ' CONF_REFRESH_DELAY=%s', name, node_config,
                  refresh, delay)
    if value.command_class != zwave.const.COMMAND_CLASS_SWITCH_MULTILEVEL:
        return
    if value.type != zwave.const.TYPE_BYTE:
        return
    if value.genre != zwave.const.GENRE_USER:
        return

    value.set_change_verified(False)

    if node.has_command_class(zwave.const.COMMAND_CLASS_SWITCH_COLOR):
        add_devices([ZwaveColorLight(value, refresh, delay)])
    else:
        add_devices([ZwaveDimmer(value, refresh, delay)])
Exemplo n.º 5
0
def get_device(node, values, node_config, **kwargs):
    """Create Z-Wave entity device."""
    name = '{}.{}'.format(DOMAIN, zwave.object_id(values.primary))
    refresh = node_config.get(zwave.CONF_REFRESH_VALUE)
    delay = node_config.get(zwave.CONF_REFRESH_DELAY)
    _LOGGER.debug("name=%s node_config=%s CONF_REFRESH_VALUE=%s"
                  " CONF_REFRESH_DELAY=%s", name, node_config, refresh, delay)

    if node.has_command_class(zwave.const.COMMAND_CLASS_SWITCH_COLOR):
        return ZwaveColorLight(values, refresh, delay)
    else:
        return ZwaveDimmer(values, refresh, delay)
Exemplo n.º 6
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: {}}
Exemplo n.º 7
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: {}}