示例#1
0
async def test_light(mock_gateway):
    """Test a Dynalite channel that is a light."""
    name = "NAME"
    channel_name = "CHANNEL"
    [device] = mock_gateway.configure_dyn_dev({
        dyn_const.CONF_ACTIVE: False,
        dyn_const.CONF_AREA: {
            "1": {
                dyn_const.CONF_NAME: name,
                dyn_const.CONF_NO_DEFAULT: True,
                dyn_const.CONF_CHANNEL: {
                    "1": {
                        dyn_const.CONF_NAME: channel_name,
                        dyn_const.CONF_FADE: 0.5,
                    }
                },
            }
        },
    })
    assert await mock_gateway.async_setup_dyn_dev()
    assert device.category == "light"
    assert device.name == f"{name} {channel_name}"
    assert device.unique_id == "dynalite_area_1_channel_1"
    assert device.available
    assert device.area_name == name
    assert device.get_master_area == name
    await device.async_turn_on()
    await mock_gateway.check_single_write(
        DynetPacket.set_channel_level_packet(1, 1, 1.0, 0.5))
    assert device.brightness == 255
    await device.async_turn_on(brightness=51)
    await mock_gateway.check_single_write(
        DynetPacket.set_channel_level_packet(1, 1, 0.2, 0.5))
    assert device.brightness == 51
    await device.async_turn_off()
    await mock_gateway.check_single_write(
        DynetPacket.set_channel_level_packet(1, 1, 0, 0.5))
    assert device.brightness == 0
    # Now send commands
    await mock_gateway.receive(
        DynetPacket.set_channel_level_packet(1, 1, 1.0, 0.5))
    assert device.brightness == 255
    assert device.is_on
    await mock_gateway.receive(
        DynetPacket.set_channel_level_packet(1, 1, 0.2, 0.5))
    assert device.brightness == 51
    assert device.is_on
    await mock_gateway.receive(
        DynetPacket.report_channel_level_packet(1, 1, 0, 0))
    assert device.brightness == 0
    assert not device.is_on
示例#2
0
def report_channel_func(area, channel):
    """Create channel report level packet."""
    return DynetPacket.report_channel_level_packet(area, channel, 1, 1)
示例#3
0
async def test_cover_no_tilt(mock_gateway):
    """Test basic cover functionality."""
    name = "NAME"
    [
        channel_device,
        open_device,
        close_device,
        stop_device,
        cover_device,
    ] = mock_gateway.configure_dyn_dev(
        {
            dyn_const.CONF_ACTIVE: False,
            dyn_const.CONF_POLL_TIMER: 0.05,
            dyn_const.CONF_AREA: {
                "1": {
                    dyn_const.CONF_NAME: name,
                    dyn_const.CONF_TEMPLATE: dyn_const.CONF_TIME_COVER,
                    dyn_const.CONF_DURATION: 0.5,
                    dyn_const.CONF_OPEN_PRESET: 1,
                    dyn_const.CONF_CLOSE_PRESET: 2,
                    dyn_const.CONF_STOP_PRESET: 3,
                    dyn_const.CONF_CHANNEL_COVER: 4,
                    dyn_const.CONF_CHANNEL: {
                        "4": {}
                    },
                    dyn_const.CONF_PRESET: {
                        "1": {},
                        "2": {},
                        "3": {}
                    },
                }
            },
        },
        5,
    )
    assert await mock_gateway.async_setup_dyn_dev()
    assert channel_device.category == "light"
    assert open_device.category == "switch"
    assert close_device.category == "switch"
    assert stop_device.category == "switch"
    assert cover_device.category == "cover"
    assert cover_device.name == name
    assert cover_device.unique_id == "dynalite_area_1_time_cover"
    assert cover_device.available
    assert cover_device.area_name == name
    assert cover_device.get_master_area == name
    assert not cover_device.has_tilt
    assert cover_device.device_class == dyn_const.DEFAULT_COVER_CLASS
    # It is closed. Let's open
    assert cover_device.is_closed
    await cover_device.async_open_cover()
    await mock_gateway.check_single_write(
        DynetPacket.select_area_preset_packet(1, 1, 0))
    assert open_device.is_on
    assert not close_device.is_on
    assert not stop_device.is_on
    await asyncio.sleep(0.25)
    assert cover_device.is_opening
    assert 40 < cover_device.current_cover_position < 60
    await asyncio.sleep(0.4)
    assert (not cover_device.is_closed and not cover_device.is_opening
            and not cover_device.is_closing)
    assert cover_device.current_cover_position == 100
    # It is open. Now let's close
    await cover_device.async_close_cover()
    await mock_gateway.check_single_write(
        DynetPacket.select_area_preset_packet(1, 2, 0))
    assert close_device.is_on
    assert not open_device.is_on
    assert not stop_device.is_on
    await asyncio.sleep(0.25)
    assert cover_device.is_closing
    assert 40 < cover_device.current_cover_position < 60
    # Stop halfway
    await cover_device.async_stop_cover()
    await mock_gateway.check_single_write(
        DynetPacket.select_area_preset_packet(1, 3, 0))
    assert stop_device.is_on
    assert not open_device.is_on
    assert not close_device.is_on
    assert (not cover_device.is_closed and not cover_device.is_opening
            and not cover_device.is_closing)
    # And continue to full close
    await cover_device.async_close_cover()
    await mock_gateway.check_single_write(
        DynetPacket.select_area_preset_packet(1, 2, 0))
    await asyncio.sleep(0.4)
    assert cover_device.is_closed
    assert cover_device.current_cover_position == 0
    # Now open it half-way
    await cover_device.async_set_cover_position(position=50)
    assert (not cover_device.is_closed and not cover_device.is_opening
            and not cover_device.is_closing)
    assert 40 < cover_device.current_cover_position < 60
    await cover_device.async_set_cover_position(position=25)
    assert (not cover_device.is_closed and not cover_device.is_opening
            and not cover_device.is_closing)
    assert 15 < cover_device.current_cover_position < 35
    await cover_device.async_open_cover()
    await asyncio.sleep(0.01)
    assert cover_device.is_opening
    mock_gateway.reset()
    await cover_device.async_set_cover_position(
        position=cover_device.current_cover_position)
    await mock_gateway.check_single_write(
        DynetPacket.select_area_preset_packet(1, 3, 0))
    assert (not cover_device.is_closed and not cover_device.is_opening
            and not cover_device.is_closing)
    # Now send commands
    await mock_gateway.receive(DynetPacket.report_area_preset_packet(1, 1))
    assert cover_device.is_opening
    await mock_gateway.receive(DynetPacket.report_area_preset_packet(1, 2))
    assert cover_device.is_closing
    await mock_gateway.receive(DynetPacket.report_area_preset_packet(1, 3))
    assert not cover_device.is_closing and not cover_device.is_opening
    await mock_gateway.receive(DynetPacket.report_area_preset_packet(1, 1))
    await asyncio.sleep(0.3)
    await mock_gateway.receive(
        DynetPacket.report_channel_level_packet(1, 4, 0, 1))
    assert cover_device.is_closing
    await asyncio.sleep(0.01)
    # Open and then stop with channel
    await mock_gateway.receive(
        DynetPacket.report_channel_level_packet(1, 4, 1, 0))
    assert cover_device.is_opening
    await mock_gateway.receive(DynetPacket.stop_channel_fade_packet(1, 4))
    assert not cover_device.is_opening
    assert not cover_device.is_closing
    # Open and then stop with area (channel=0xff)
    await mock_gateway.receive(
        DynetPacket.report_channel_level_packet(1, 4, 0, 1))
    await mock_gateway.receive(
        DynetPacket.report_channel_level_packet(1, 4, 1, 0))
    assert cover_device.is_opening
    await mock_gateway.receive(DynetPacket.stop_channel_fade_packet(1, 256))
    assert not cover_device.is_opening
    assert not cover_device.is_closing