Ejemplo n.º 1
0
def test_get_desired_value():
    """Test that sensor returns correct desired value in different states."""
    const = get_const("1.4")
    sensor_id = 1
    child_id = 0
    value_type = const.SetReq.V_LIGHT_LEVEL
    wrong_child_id = 100
    wrong_value_type = 9999

    sensor = Sensor(sensor_id)
    sensor.add_child_sensor(child_id, const.Presentation.S_LIGHT_LEVEL)

    assert sensor.get_desired_value(child_id, value_type) is None

    sensor.update_child_value(child_id, value_type, "50")
    assert sensor.get_desired_value(child_id, value_type) == "50"

    sensor.init_smart_sleep_mode()

    sensor.set_child_desired_state(child_id, value_type, "90")
    assert sensor.get_desired_value(child_id, value_type) == "90"

    sensor.update_child_value(child_id, value_type, "70")
    assert sensor.get_desired_value(child_id, value_type) == "70"

    assert sensor.get_desired_value(wrong_child_id, value_type) is None
    assert sensor.get_desired_value(child_id, wrong_value_type) is None
Ejemplo n.º 2
0
def test_update_child_value_resets_new_state():
    """Test that update of child state resets the new state."""
    const = get_const("1.4")
    sensor_id = 1
    child_id = 0
    value_type = const.SetReq.V_LIGHT_LEVEL

    sensor = Sensor(sensor_id)
    sensor.add_child_sensor(child_id, const.Presentation.S_LIGHT_LEVEL)
    sensor.init_smart_sleep_mode()
    sensor.set_child_desired_state(child_id, value_type, "50")

    assert sensor.new_state[child_id].values[value_type] == "50"

    sensor.update_child_value(child_id, value_type, "60")

    assert sensor.new_state[child_id].values[value_type] is None
Ejemplo n.º 3
0
def test_get_desired_value_empty_string():
    """Test that sensor returns correct value if the desired state is empty string."""
    const = get_const("1.4")
    sensor_id = 1
    child_id = 0
    value_type = const.SetReq.V_VAR1

    sensor = Sensor(sensor_id)
    sensor.add_child_sensor(child_id, const.Presentation.S_CUSTOM)

    assert sensor.get_desired_value(child_id, value_type) is None

    sensor.update_child_value(child_id, value_type, "Some string")
    assert sensor.get_desired_value(child_id, value_type) == "Some string"

    sensor.init_smart_sleep_mode()

    sensor.set_child_desired_state(child_id, value_type, "")
    assert sensor.get_desired_value(child_id, value_type) == ""
Ejemplo n.º 4
0
def test_update_child_value():
    """Test that we can update child state."""
    const = get_const("1.4")
    sensor_id = 1
    child_id = 0
    wrong_child_id = 100
    value_type = const.SetReq.V_LIGHT_LEVEL

    sensor = Sensor(sensor_id)
    sensor.add_child_sensor(child_id, const.Presentation.S_LIGHT_LEVEL)

    assert value_type not in sensor.children[child_id].values

    # able to set
    sensor.update_child_value(child_id, value_type, "50")
    assert sensor.children[child_id].values[value_type] == "50"

    # able to update
    sensor.update_child_value(child_id, value_type, "90")
    assert sensor.children[child_id].values[value_type] == "90"

    # does not set unknown child
    sensor.update_child_value(wrong_child_id, value_type, "50")
    assert wrong_child_id not in sensor.children