Example #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
Example #2
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) == ""