Ejemplo n.º 1
0
def test_operation_value_changed_preset(device_mapping):
    """Test preset changed for climate device."""
    device = device_mapping
    assert device.hvac_mode == HVAC_MODE_HEAT
    assert device.preset_mode == PRESET_NONE
    device.values.primary.data = PRESET_ECO
    value_changed(device.values.primary)
    assert device.hvac_mode == HVAC_MODE_HEAT_COOL
    assert device.preset_mode == PRESET_ECO
async def test_network_node_changed_from_value(hass, mock_openzwave):
    """Test for network_node_changed."""
    zwave_network = MagicMock()
    node = mock_zwave.MockNode()
    entity = node_entity.ZWaveNodeEntity(node, zwave_network)
    value = mock_zwave.MockValue(node=node)
    with patch.object(entity, "maybe_schedule_update") as mock:
        mock_zwave.value_changed(value)
        mock.assert_called_once_with()
Ejemplo n.º 3
0
def test_temperature_unit(device):
    """Test temperature unit."""
    assert device.temperature_unit == TEMP_CELSIUS
    device.values.temperature.units = "F"
    value_changed(device.values.temperature)
    assert device.temperature_unit == TEMP_FAHRENHEIT
    device.values.temperature.units = "C"
    value_changed(device.values.temperature)
    assert device.temperature_unit == TEMP_CELSIUS
Ejemplo n.º 4
0
def test_temperature_unit(device):
    """Test temperature unit."""
    assert device.temperature_unit == TEMP_CELSIUS
    device.values.temperature.units = 'F'
    value_changed(device.values.temperature)
    assert device.temperature_unit == TEMP_FAHRENHEIT
    device.values.temperature.units = 'C'
    value_changed(device.values.temperature)
    assert device.temperature_unit == TEMP_CELSIUS
Ejemplo n.º 5
0
def test_operation_value_changed_unknown(device_unknown):
    """Test preset changed for climate device. Unknown."""
    device = device_unknown
    assert device.hvac_mode == HVAC_MODE_HEAT
    assert device.preset_mode == PRESET_NONE
    device.values.primary.data = "Abcdefg"
    value_changed(device.values.primary)
    assert device.hvac_mode == HVAC_MODE_HEAT_COOL
    assert device.preset_mode == "Abcdefg"
Ejemplo n.º 6
0
def test_aux_heat_value_changed(device_aux_heat):
    """Test aux heat for climate device."""
    device = device_aux_heat
    assert device.is_aux_heat is False
    device.values.primary.data = AUX_HEAT_ZWAVE_MODE
    value_changed(device.values.primary)
    assert device.is_aux_heat is True
    device.values.primary.data = HVAC_MODE_HEAT
    value_changed(device.values.primary)
    assert device.is_aux_heat is False
Ejemplo n.º 7
0
def test_target_changed_with_mode(device):
    """Test values changed for climate device."""
    assert device.hvac_mode == HVAC_MODE_HEAT
    assert device.target_temperature == 1
    device.values.primary.data = HVAC_MODE_COOL
    value_changed(device.values.primary)
    assert device.target_temperature == 10
    device.values.primary.data = HVAC_MODE_HEAT_COOL
    value_changed(device.values.primary)
    assert device.target_temperature_low == 1
    assert device.target_temperature_high == 10
Ejemplo n.º 8
0
def test_operation_value_changed_mapping_preset(device_mapping):
    """Test values changed for climate device. Mapping with presets."""
    device = device_mapping
    assert device.hvac_mode == HVAC_MODE_HEAT
    assert device.preset_mode == PRESET_NONE
    device.values.primary.data = "Full Power"
    value_changed(device.values.primary)
    assert device.hvac_mode == HVAC_MODE_HEAT_COOL
    assert device.preset_mode == PRESET_BOOST
    device.values.primary = None
    assert device.hvac_mode == HVAC_MODE_HEAT_COOL
    assert device.preset_mode == PRESET_NONE
Ejemplo n.º 9
0
def test_target_range_changed(device_heat_cool_range):
    """Test values changed for climate device."""
    device = device_heat_cool_range
    assert device.target_temperature_low == 1
    assert device.target_temperature_high == 10
    device.values.setpoint_heating.data = 2
    value_changed(device.values.setpoint_heating)
    assert device.target_temperature_low == 2
    assert device.target_temperature_high == 10
    device.values.setpoint_cooling.data = 9
    value_changed(device.values.setpoint_cooling)
    assert device.target_temperature_low == 2
    assert device.target_temperature_high == 9
Ejemplo n.º 10
0
def test_operation_value_changed_mapping(device_mapping):
    """Test values changed for climate device. Mapping."""
    device = device_mapping
    assert device.hvac_mode == HVAC_MODE_HEAT
    assert device.preset_mode == PRESET_NONE
    device.values.primary.data = "Off"
    value_changed(device.values.primary)
    assert device.hvac_mode == HVAC_MODE_OFF
    assert device.preset_mode == PRESET_NONE
    device.values.primary.data = "Cool"
    value_changed(device.values.primary)
    assert device.hvac_mode == HVAC_MODE_COOL
    assert device.preset_mode == PRESET_NONE
Ejemplo n.º 11
0
def test_operation_value_changed_heat_cool(device_heat_cool):
    """Test preset changed for climate device. Heat/Cool only."""
    device = device_heat_cool
    assert device.hvac_mode == HVAC_MODE_HEAT
    assert device.preset_mode == PRESET_NONE
    device.values.primary.data = "Cool Eco"
    value_changed(device.values.primary)
    assert device.hvac_mode == HVAC_MODE_COOL
    assert device.preset_mode == "Cool Eco"
    device.values.primary.data = "Heat Eco"
    value_changed(device.values.primary)
    assert device.hvac_mode == HVAC_MODE_HEAT
    assert device.preset_mode == "Heat Eco"
Ejemplo n.º 12
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
Ejemplo n.º 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
Ejemplo n.º 14
0
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
Ejemplo n.º 15
0
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
Ejemplo n.º 16
0
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
Ejemplo n.º 17
0
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
Ejemplo n.º 18
0
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
Ejemplo n.º 19
0
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
Ejemplo n.º 20
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
Ejemplo n.º 21
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
Ejemplo n.º 22
0
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
Ejemplo n.º 23
0
def test_lock_state_workaround(mock_openzwave):
    """Test value changed for Z-Wave lock using notification state."""
    node = MockNode(manufacturer_id='0090', product_id='0440')
    values = MockEntityValues(
        primary=MockValue(data=True, node=node),
        access_control=MockValue(data=1, node=node),
        alarm_type=None,
        alarm_level=None,
    )
    device = zwave.get_device(node=node, values=values)
    assert device.is_locked
    values.access_control.data = 2
    value_changed(values.access_control)
    assert not device.is_locked
Ejemplo n.º 24
0
def test_target_value_set_single_setpoint(device_single_setpoint):
    """Test values changed for climate device."""
    device = device_single_setpoint
    assert device.values.primary.data == 1
    device.set_temperature(**{ATTR_TEMPERATURE: 2})
    assert device.values.setpoint_heating.data == 2
    assert device.values.setpoint_cooling.data == 10
    device.set_hvac_mode(HVAC_MODE_COOL)
    value_changed(device.values.primary)
    assert device.values.setpoint_heating.data == 2
    assert device.values.setpoint_cooling.data == 10
    device.set_temperature(**{ATTR_TEMPERATURE: 9})
    assert device.values.setpoint_heating.data == 2
    assert device.values.setpoint_cooling.data == 9
Ejemplo n.º 25
0
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
Ejemplo n.º 26
0
def test_lock_state_workaround(mock_openzwave):
    """Test value changed for Z-Wave lock using notification state."""
    node = MockNode(manufacturer_id="0090", product_id="0440")
    values = MockEntityValues(
        primary=MockValue(data=True, node=node),
        access_control=MockValue(data=1, node=node),
        alarm_type=None,
        alarm_level=None,
    )
    device = lock.get_device(node=node, values=values)
    assert device.is_locked
    values.access_control.data = 2
    value_changed(values.access_control)
    assert not device.is_locked
Ejemplo n.º 27
0
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
Ejemplo n.º 28
0
def test_lock_alarm_type(mock_openzwave):
    """Test alarm type 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=None,
    )
    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
    value_changed(values.alarm_type)
    assert (
        device.extra_state_attributes[lock.ATTR_LOCK_STATUS] == "Manually Locked None"
    )

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

    values.alarm_type.data = 161
    value_changed(values.alarm_type)
    assert device.extra_state_attributes[lock.ATTR_LOCK_STATUS] == "Tamper Alarm: None"

    values.alarm_type.data = 9
    value_changed(values.alarm_type)
    assert device.extra_state_attributes[lock.ATTR_LOCK_STATUS] == "Deadbolt Jammed"
Ejemplo n.º 29
0
def test_lock_alarm_type(mock_openzwave):
    """Test alarm type 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=None,
    )
    device = zwave.get_device(node=node, values=values, node_config={})

    assert zwave.ATTR_LOCK_STATUS not in device.device_state_attributes

    values.alarm_type.data = 21
    value_changed(values.alarm_type)
    assert device.device_state_attributes[zwave.ATTR_LOCK_STATUS] == \
        'Manually Locked None'

    values.alarm_type.data = 18
    value_changed(values.alarm_type)
    assert device.device_state_attributes[zwave.ATTR_LOCK_STATUS] == \
        'Locked with Keypad by user None'

    values.alarm_type.data = 161
    value_changed(values.alarm_type)
    assert device.device_state_attributes[zwave.ATTR_LOCK_STATUS] == \
        'Tamper Alarm: None'

    values.alarm_type.data = 9
    value_changed(values.alarm_type)
    assert device.device_state_attributes[zwave.ATTR_LOCK_STATUS] == \
        'Deadbolt Jammed'
Ejemplo n.º 30
0
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
Ejemplo n.º 31
0
def test_operation_value_changed(device):
    """Test values changed for climate device."""
    assert device.hvac_mode == HVAC_MODE_HEAT
    assert device.preset_mode == PRESET_NONE
    device.values.primary.data = HVAC_MODE_COOL
    value_changed(device.values.primary)
    assert device.hvac_mode == HVAC_MODE_COOL
    assert device.preset_mode == PRESET_NONE
    device.values.primary.data = HVAC_MODE_OFF
    value_changed(device.values.primary)
    assert device.hvac_mode == HVAC_MODE_OFF
    assert device.preset_mode == PRESET_NONE
    device.values.primary = None
    assert device.hvac_mode == HVAC_MODE_HEAT_COOL
    assert device.preset_mode == PRESET_NONE
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 = binary_sensor.get_device(node=node, values=values, node_config={})

    assert not device.is_on

    value.data = True
    value_changed(value)

    assert device.is_on
Ejemplo n.º 33
0
def test_multilevelsensor_value_changed_other_units(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=190.95555, units="kWh", node=node)
    values = MockEntityValues(primary=value)

    device = sensor.get_device(node=node, values=values, node_config={})
    assert device.state == 190.96
    assert device.unit_of_measurement == "kWh"
    value.data = 197.95555
    value_changed(value)
    assert device.state == 197.96
Ejemplo n.º 34
0
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 = light.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)
Ejemplo n.º 35
0
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]
Ejemplo n.º 36
0
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='#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 = '#c86400c800'
    value_changed(color)

    assert device.rgb_color == [200, 150, 100]
Ejemplo n.º 37
0
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)
Ejemplo n.º 38
0
def test_lock_value_changed(mock_openzwave):
    """Test value changed for Z-Wave lock."""
    node = MockNode()
    values = MockEntityValues(
        primary=MockValue(data=None, node=node),
        access_control=None,
        alarm_type=None,
        alarm_level=None,
    )
    device = zwave.get_device(node=node, values=values, node_config={})

    assert not device.is_locked

    values.primary.data = True
    value_changed(values.primary)

    assert device.is_locked
Ejemplo n.º 39
0
def test_lock_value_changed(mock_openzwave):
    """Test value changed for Z-Wave lock."""
    node = MockNode()
    values = MockEntityValues(
        primary=MockValue(data=None, node=node),
        access_control=None,
        alarm_type=None,
        alarm_level=None,
    )
    device = lock.get_device(node=node, values=values, node_config={})

    assert not device.is_locked

    values.primary.data = True
    value_changed(values.primary)

    assert device.is_locked
Ejemplo n.º 40
0
def test_zxt_120_swing_mode(device_zxt_120):
    """Test operation of the zxt 120 swing mode."""
    device = device_zxt_120

    assert device.swing_list == [6, 7, 8]
    assert device._zxt_120 == 1

    # Test set mode
    assert device.values.zxt_120_swing_mode.data == b'test3'
    device.set_swing_mode('test_swing_set')
    assert device.values.zxt_120_swing_mode.data == b'test_swing_set'

    # Test mode changed
    value_changed(device.values.zxt_120_swing_mode)
    assert device.current_swing_mode == b'test_swing_set'
    device.values.zxt_120_swing_mode.data = b'test_swing_updated'
    value_changed(device.values.zxt_120_swing_mode)
    assert device.current_swing_mode == b'test_swing_updated'
Ejemplo n.º 41
0
def test_zxt_120_swing_mode(device_zxt_120):
    """Test operation of the zxt 120 swing mode."""
    device = device_zxt_120

    assert device.swing_list == [6, 7, 8]
    assert device._zxt_120 == 1

    # Test set mode
    assert device.values.zxt_120_swing_mode.data == 'test3'
    device.set_swing_mode('test_swing_set')
    assert device.values.zxt_120_swing_mode.data == 'test_swing_set'

    # Test mode changed
    value_changed(device.values.zxt_120_swing_mode)
    assert device.current_swing_mode == 'test_swing_set'
    device.values.zxt_120_swing_mode.data = 'test_swing_updated'
    value_changed(device.values.zxt_120_swing_mode)
    assert device.current_swing_mode == 'test_swing_updated'
Ejemplo n.º 42
0
def test_zxt_120_swing_mode(device_zxt_120):
    """Test operation of the zxt 120 swing mode."""
    device = device_zxt_120

    assert device.swing_modes == [6, 7, 8]
    assert device._zxt_120 == 1

    # Test set mode
    assert device.values.zxt_120_swing_mode.data == "test3"
    device.set_swing_mode("test_swing_set")
    assert device.values.zxt_120_swing_mode.data == "test_swing_set"

    # Test mode changed
    value_changed(device.values.zxt_120_swing_mode)
    assert device.swing_mode == "test_swing_set"
    device.values.zxt_120_swing_mode.data = "test_swing_updated"
    value_changed(device.values.zxt_120_swing_mode)
    assert device.swing_mode == "test_swing_updated"
Ejemplo n.º 43
0
def test_v2btze_value_changed(mock_openzwave):
    """Test value changed for v2btze Z-Wave lock."""
    node = MockNode(manufacturer_id='010e', product_id='0002')
    values = MockEntityValues(
        primary=MockValue(data=None, node=node),
        v2btze_advanced=MockValue(data='Advanced', node=node),
        access_control=MockValue(data=19, node=node),
        alarm_type=None,
        alarm_level=None,
    )
    device = zwave.get_device(node=node, values=values, node_config={})
    assert device._v2btze

    assert not device.is_locked

    values.access_control.data = 24
    value_changed(values.primary)

    assert device.is_locked
Ejemplo n.º 44
0
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
Ejemplo n.º 45
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
Ejemplo n.º 46
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 = 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
Ejemplo n.º 47
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
Ejemplo n.º 48
0
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
Ejemplo n.º 49
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 = 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
Ejemplo n.º 50
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)
    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
Ejemplo n.º 51
0
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'
Ejemplo n.º 52
0
def test_operation_value_changed_mapping(device_mapping):
    """Test values changed for climate device. Mapping."""
    device = device_mapping
    assert device.current_operation == 'off'
    device.values.mode.data = 'Heat'
    value_changed(device.values.mode)
    assert device.current_operation == STATE_HEAT
    device.values.mode.data = 'Cool'
    value_changed(device.values.mode)
    assert device.current_operation == STATE_COOL
    device.values.mode.data = 'Off'
    value_changed(device.values.mode)
    assert device.current_operation == STATE_OFF
Ejemplo n.º 53
0
def test_operating_state_value_changed(device):
    """Test values changed for climate device."""
    assert device.device_state_attributes[zwave.ATTR_OPERATING_STATE] == 6
    device.values.operating_state.data = 8
    value_changed(device.values.operating_state)
    assert device.device_state_attributes[zwave.ATTR_OPERATING_STATE] == 8
Ejemplo n.º 54
0
def test_fan_state_value_changed(device):
    """Test values changed for climate device."""
    assert device.device_state_attributes[zwave.ATTR_FAN_STATE] == 7
    device.values.fan_state.data = 9
    value_changed(device.values.fan_state)
    assert device.device_state_attributes[zwave.ATTR_FAN_STATE] == 9
Ejemplo n.º 55
0
def test_default_target_temperature(device):
    """Test default setting of target temperature."""
    assert device.target_temperature == 1
    device.values.primary.data = 0
    value_changed(device.values.primary)
    assert device.target_temperature == 5  # Current Temperature