예제 #1
0
    def test_is_dirty(self):
        """Test the is_dirty property."""

        address = random_address()
        ramp_rate_prop = ExtendedProperty(address, "ramp_rate", RampRate,
                                          False, False, PropertyType.ADVANCED)
        test_prop = RampRateProperty(address, "test_prop", ramp_rate_prop)

        assert not ramp_rate_prop.is_dirty
        assert not test_prop.is_dirty
        ramp_rate_prop.load(0)
        assert not ramp_rate_prop.is_dirty
        assert not test_prop.is_dirty
        ramp_rate_prop.new_value = RampRate.MIN_1
        assert ramp_rate_prop.is_dirty
        assert test_prop.is_dirty
        ramp_rate_prop.new_value = None
        assert not ramp_rate_prop.is_dirty
        assert not test_prop.is_dirty
        ramp_rate_prop.new_value = RampRate.MIN_1_5
        assert ramp_rate_prop.is_dirty
        assert test_prop.is_dirty
        ramp_rate_prop.new_value = ramp_rate_prop.value
        assert not ramp_rate_prop.is_dirty
        assert not test_prop.is_dirty
예제 #2
0
async def test_get_read_only_properties(hass, hass_ws_client, iolinc_properties_data):
    """Test getting an Insteon device's properties."""
    mock_read_only = ExtendedProperty(
        "44.44.44", "mock_read_only", bool, is_read_only=True
    )
    mock_read_only.load(False)

    ws_client, devices = await _setup(
        hass, hass_ws_client, "44.44.44", iolinc_properties_data
    )
    device = devices["44.44.44"]
    device.configuration["mock_read_only"] = mock_read_only
    with patch.object(insteon.api.properties, "devices", devices):
        await ws_client.send_json(
            {
                ID: 2,
                TYPE: "insteon/properties/get",
                DEVICE_ADDRESS: "44.44.44",
                SHOW_ADVANCED: False,
            }
        )
        msg = await ws_client.receive_json()
        assert msg["success"]
        assert len(msg["result"]["properties"]) == 6
        await ws_client.send_json(
            {
                ID: 3,
                TYPE: "insteon/properties/get",
                DEVICE_ADDRESS: "44.44.44",
                SHOW_ADVANCED: True,
            }
        )
        msg = await ws_client.receive_json()
        assert msg["success"]
        assert len(msg["result"]["properties"]) == 15
예제 #3
0
    def test_value(self):
        """Test the ramp rate value."""
        address = random_address()
        ramp_rate_prop = ExtendedProperty(address, "ramp_rate", RampRate,
                                          False, False, PropertyType.ADVANCED)
        test_prop = RampRateProperty(address, "test_prop", ramp_rate_prop)

        assert ramp_rate_prop.value is None
        test_prop.value is None
        ramp_rate_prop.load(RampRate.MIN_4)
        assert test_prop.value == ramp_rate_to_seconds(RampRate.MIN_4)
예제 #4
0
    def test_is_loaded(self):
        """Test the is_dirty property."""

        address = random_address()
        ramp_rate_prop = ExtendedProperty(address, "ramp_rate", RampRate,
                                          False, False, PropertyType.ADVANCED)
        test_prop = RampRateProperty(address, "test_prop", ramp_rate_prop)

        assert not ramp_rate_prop.is_loaded
        assert not test_prop.is_loaded

        ramp_rate_prop.load(RampRate.MIN_1)
        assert ramp_rate_prop.is_loaded
        assert test_prop.is_loaded
예제 #5
0
    def test_new_value(self):
        """Test setting a new value."""
        address = random_address()
        delay_prop = ExtendedProperty(address, "delay", int, False, False,
                                      PropertyType.ADVANCED)
        prescaler_prop = ExtendedProperty(address, "delay", int, False, False,
                                          PropertyType.ADVANCED)

        test_prop = MomentaryDelayProperty(address, "test_prop", delay_prop,
                                           prescaler_prop)
        delay_prop.load(0)
        prescaler_prop.load(0)
        assert test_prop.new_value is None

        # Test small number delays (< 255).  Result should be exact
        for delay_value in range(1, 255):
            test_prop.new_value = delay_value / 10
            assert test_prop.new_value == delay_value / 10
            assert delay_prop.new_value == delay_value
            assert prescaler_prop.new_value == 1

        # Test a set of larger number
        for _ in range(0, 20):
            delay_value = randint(26, 255)
            prescaler_value = randint(1, 255)
            seconds = delay_value * max(1, prescaler_value) / 10
            test_prop.new_value = seconds
            assert (delay_prop.new_value * prescaler_prop.new_value /
                    10 == test_prop.new_value)

        # Test setting new_value to value
        delay_value = randint(1, 20)
        prescaler_value = 1
        new_delay_value = randint(21, 50)
        seconds = delay_value / 10
        new_seconds = new_delay_value / 10

        # Set delay in seconds to seconds
        delay_prop.load(delay_value)
        prescaler_prop.load(prescaler_value)
        assert test_prop.value == seconds

        # Set new_value to new_seconds
        test_prop.new_value = new_seconds
        assert test_prop.new_value == new_seconds
        assert delay_prop.new_value == new_delay_value

        # Set new_value to seconds and confirm new_value is None
        test_prop.new_value = seconds
        assert test_prop.new_value is None
        assert delay_prop.new_value is None

        # Test too large and too small a number
        for val in [10000, -1]:
            try:
                test_prop.new_value = val
                assert False
            except ValueError:
                assert True
예제 #6
0
    def test_load(self):
        """Test the is_loaded property."""
        address = random_address()
        delay_prop = ExtendedProperty(address, "delay", int, False, False,
                                      PropertyType.ADVANCED)
        prescaler_prop = ExtendedProperty(address, "delay", int, False, False,
                                          PropertyType.ADVANCED)

        test_prop = MomentaryDelayProperty(address, "test_prop", delay_prop,
                                           prescaler_prop)
        assert not test_prop.is_loaded
        delay_prop.load(0)
        assert not test_prop.is_loaded
        prescaler_prop.load(0)
        assert test_prop.is_loaded
예제 #7
0
    def test_new_value(self):
        """Test the new_value property."""

        address = random_address()
        ramp_rate_prop = ExtendedProperty(address, "ramp_rate", RampRate,
                                          False, False, PropertyType.ADVANCED)
        test_prop = RampRateProperty(address, "test_prop", ramp_rate_prop)
        assert ramp_rate_prop.new_value is None
        assert test_prop.new_value is None

        # Test all ramp rates except 0 and 2
        for value in range(1, 0x1F):
            if value == 2:  # Special condition
                continue
            ramp_rate = RampRate(value)
            seconds = ramp_rate_to_seconds(ramp_rate)
            test_prop.new_value = seconds
            assert ramp_rate_prop.new_value == ramp_rate
            assert test_prop.new_value == seconds

        # Test 0 and 2
        for value in [0, 2]:
            seconds = ramp_rate_to_seconds(value)
            test_prop.new_value = seconds
            assert ramp_rate_prop.new_value == seconds_to_ramp_rate(seconds)

        # Test clearing the changes
        test_prop.new_value = None
        assert ramp_rate_prop.new_value is None

        test_prop.new_value = 3
        ramp_rate_prop.new_value = None
        assert test_prop.new_value is None

        # Test putting new_value to current value
        seconds = ramp_rate_to_seconds(RampRate.SEC_0_3)
        ramp_rate_prop.load(RampRate.SEC_0_3)
        assert test_prop.value == seconds
        seconds2 = seconds + 2
        ramp_rate2 = seconds_to_ramp_rate(seconds2)
        test_prop.new_value = seconds2
        assert ramp_rate_prop.new_value == ramp_rate2
        assert test_prop.new_value == ramp_rate_to_seconds(ramp_rate2)
        test_prop.new_value = test_prop.value
        assert test_prop.new_value is None
        assert ramp_rate_prop.new_value is None
예제 #8
0
    def test_value(self):
        """Test the momentary delay value."""
        address = random_address()
        delay_prop = ExtendedProperty(address, "delay", int, False, False,
                                      PropertyType.ADVANCED)
        prescaler_prop = ExtendedProperty(address, "delay", int, False, False,
                                          PropertyType.ADVANCED)

        test_prop = MomentaryDelayProperty(address, "test_prop", delay_prop,
                                           prescaler_prop)

        delay_value = randint(0, 255)
        prescaler_value = randint(0, 255)
        delay_prop.load(delay_value)
        prescaler_prop.load(prescaler_value)
        seconds = delay_value * max(1, prescaler_value) / 10

        assert test_prop.value == seconds
예제 #9
0
    def test_new_value(self):
        """Test the new_value property."""
        address = random_address()
        non_toggle_prop = ExtendedProperty(address, "non_toggle", int, False,
                                           False, PropertyType.ADVANCED)
        on_only_prop = ExtendedProperty(address, "on_only", int, False, False,
                                        PropertyType.ADVANCED)

        for button in range(2, 8):
            test_prop = ToggleButtonProperty(
                address,
                "test_prop",
                button,
                non_toggle_prop,
                on_only_prop,
            )

            # Test the new_value is calculated correctly from the underlying properties
            for toggle_mode, test_values in test_toggle_mode_to_prop.items():
                non_toggle_prop.load(set_bit(0, button - 1,
                                             not test_values[0]))
                on_only_prop.load(set_bit(0, button - 1, not test_values[1]))
                assert test_prop.new_value is None
                non_toggle_prop.new_value = set_bit(0, button - 1,
                                                    test_values[0])
                on_only_prop.new_value = set_bit(0, button - 1, test_values[1])
                assert test_prop.new_value == toggle_mode

            # Test the underlying properties are set correctly
            for toggle_mode, test_values in test_toggle_mode_to_prop.items():
                non_toggle_prop.load(set_bit(0, button - 1,
                                             not test_values[0]))
                on_only_prop.load(set_bit(0, button - 1, not test_values[1]))
                assert test_prop.new_value is None
                test_prop.new_value = toggle_mode
                assert non_toggle_prop.new_value == set_bit(
                    0, button - 1, test_values[0])
                assert on_only_prop.new_value == set_bit(
                    0, button - 1, test_values[1])
                test_prop.new_value = None
                assert non_toggle_prop.new_value is None
                assert on_only_prop.new_value is None

                test_prop.new_value = toggle_mode
                assert non_toggle_prop.new_value == set_bit(
                    0, button - 1, test_values[0])
                assert on_only_prop.new_value == set_bit(
                    0, button - 1, test_values[1])
                test_prop.new_value = test_prop.value
                assert non_toggle_prop.new_value is None
                assert on_only_prop.new_value is None
예제 #10
0
    def test_value(self):
        """Test the momentary delay value."""
        address = random_address()

        momentary_mode_on_prop = ExtendedProperty(address, "mm_on", bool,
                                                  False, False,
                                                  PropertyType.ADVANCED)
        momentary_follow_sense_prop = ExtendedProperty(address, "m_follow",
                                                       bool, False, False,
                                                       PropertyType.ADVANCED)
        momentary_on_off_trigger_prop = ExtendedProperty(
            address, "m_on_off", bool, False, False, PropertyType.ADVANCED)

        test_prop = RelayModeProperty(
            address,
            "test_prop",
            momentary_mode_on_prop,
            momentary_follow_sense_prop,
            momentary_on_off_trigger_prop,
        )

        for test_value in test_prop_to_relay_mode:
            momentary_mode_on_prop.load(test_value[0])
            momentary_follow_sense_prop.load(test_value[1])
            momentary_on_off_trigger_prop.load(test_value[2])
            assert test_prop.value == test_value[3]
예제 #11
0
    def test_is_loaded(self):
        """Test the is_loaded property."""

        address = random_address()

        momentary_mode_on_prop = ExtendedProperty(address, "mm_on", bool,
                                                  False, False,
                                                  PropertyType.ADVANCED)
        momentary_follow_sense_prop = ExtendedProperty(address, "m_follow",
                                                       bool, False, False,
                                                       PropertyType.ADVANCED)
        momentary_on_off_trigger_prop = ExtendedProperty(
            address, "m_on_off", bool, False, False, PropertyType.ADVANCED)

        test_prop = RelayModeProperty(
            address,
            "test_prop",
            momentary_mode_on_prop,
            momentary_follow_sense_prop,
            momentary_on_off_trigger_prop,
        )
        assert not test_prop.is_loaded
        momentary_mode_on_prop.load(False)
        assert not test_prop.is_loaded
        momentary_follow_sense_prop.load(False)
        assert not test_prop.is_loaded
        momentary_on_off_trigger_prop.load(False)
        assert test_prop.is_loaded
예제 #12
0
    def test_is_dirty(self):
        """Test the id_dirty property."""
        address = random_address()
        delay_prop = ExtendedProperty(address, "delay", int, False, False,
                                      PropertyType.ADVANCED)
        prescaler_prop = ExtendedProperty(address, "delay", int, False, False,
                                          PropertyType.ADVANCED)

        test_prop = MomentaryDelayProperty(address, "test_prop", delay_prop,
                                           prescaler_prop)
        assert not test_prop.is_dirty
        delay_prop.load(0)
        assert not test_prop.is_dirty
        prescaler_prop.load(0)
        assert not test_prop.is_dirty

        delay_prop.new_value = randint(1, 255)
        assert test_prop.is_dirty

        delay_prop.new_value = None
        assert not test_prop.is_dirty

        prescaler_prop.new_value = randint(1, 255)
        assert test_prop.is_dirty

        prescaler_prop.new_value = None
        assert not test_prop.is_dirty

        delay_prop.new_value = randint(1, 255)
        assert test_prop.is_dirty

        delay_prop.new_value = randint(1, 255)
        prescaler_prop.new_value = randint(1, 255)
        assert test_prop.is_dirty

        delay_prop.new_value = None
        prescaler_prop.new_value = None
        assert not test_prop.is_dirty
예제 #13
0
    def test_value(self):
        """Test the toggle button value."""
        address = random_address()

        for button in range(2, 8):
            non_toggle_prop = ExtendedProperty(address, "non_toggle", int,
                                               False, False,
                                               PropertyType.ADVANCED)
            on_only_prop = ExtendedProperty(address, "on_only", int, False,
                                            False, PropertyType.ADVANCED)
            test_prop = ToggleButtonProperty(
                address,
                "test_prop",
                button,
                non_toggle_prop,
                on_only_prop,
            )
            assert test_prop.value is None

            for toggle_mode, test_values in test_toggle_mode_to_prop.items():
                non_toggle_prop.load(set_bit(0, button - 1, test_values[0]))
                on_only_prop.load(set_bit(0, button - 1, test_values[1]))
                assert test_prop.value == toggle_mode
예제 #14
0
    def test_load_method(self):
        """Test the load method."""
        prop = ExtendedProperty(random_address(), "prop_name", int, False,
                                False)

        value = random.randint(0, 255)
        assert not prop.is_loaded
        prop.load(value)
        assert prop.is_loaded
        assert prop.value == value
        assert not prop.is_dirty
        assert prop.new_value is None

        new_value = random.randint(0, 255)
        prop.new_value = new_value
        assert prop.new_value == new_value
        assert prop.is_dirty

        value2 = random.randint(0, 255)
        prop.load(value2)
        assert prop.is_loaded
        assert prop.value == value2
        assert not prop.is_dirty
        assert prop.new_value is None
예제 #15
0
    def test_new_value(self):
        """Test the new_value property."""
        address = random_address()

        momentary_mode_on_prop = ExtendedProperty(address, "mm_on", bool,
                                                  False, False,
                                                  PropertyType.ADVANCED)
        momentary_follow_sense_prop = ExtendedProperty(address, "m_follow",
                                                       bool, False, False,
                                                       PropertyType.ADVANCED)
        momentary_on_off_trigger_prop = ExtendedProperty(
            address, "m_on_off", bool, False, False, PropertyType.ADVANCED)

        test_prop = RelayModeProperty(
            address,
            "test_prop",
            momentary_mode_on_prop,
            momentary_follow_sense_prop,
            momentary_on_off_trigger_prop,
        )

        for relay_mode, test_value in test_relay_mode_to_prop.items():
            # Make sure the new_value does not eq value otherwise no change is triggered
            momentary_mode_on_prop.load(not test_value[0])
            momentary_follow_sense_prop.load(not test_value[1])
            momentary_on_off_trigger_prop.load(not test_value[2])
            test_prop.new_value = relay_mode
            assert momentary_mode_on_prop.new_value == test_value[0]
            assert momentary_follow_sense_prop.new_value == test_value[1]
            assert momentary_on_off_trigger_prop.new_value == test_value[2]

        # Test resetting relay mode
        momentary_mode_on_prop.load(False)
        momentary_follow_sense_prop.load(False)
        momentary_on_off_trigger_prop.load(False)
        assert test_prop.value == RelayMode.LATCHING
        test_prop.new_value = RelayMode.MOMENTARY_A
        assert test_prop.new_value == RelayMode.MOMENTARY_A
        test_prop.new_value = RelayMode.LATCHING
        assert test_prop.new_value is None
        assert test_prop.value == RelayMode.LATCHING

        test_prop.new_value = RelayMode.MOMENTARY_A
        assert test_prop.new_value == RelayMode.MOMENTARY_A
        test_prop.new_value = None
        assert test_prop.new_value is None
        assert momentary_mode_on_prop.new_value is None
        assert momentary_follow_sense_prop.new_value is None
        assert momentary_on_off_trigger_prop.new_value is None