コード例 #1
0
ファイル: switch.py プロジェクト: stjordanis/core-4
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
    """Set up the device."""

    host = config[CONF_HOST]
    mac_address = config[CONF_MAC]
    device_name = config.get(CONF_NAME)

    if not hass.data.get(DATA_RSN):
        hass.data[DATA_RSN] = RSNetwork()
        job = hass.data[DATA_RSN].create_datagram_endpoint()
        hass.async_create_task(job)

    device = hass.data[DATA_RSN].register_device(mac_address, host)
    async_add_entities([RecSwitchSwitch(device, device_name, mac_address)])
コード例 #2
0
ファイル: switch.py プロジェクト: rikroe/core
async def async_setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    async_add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the device."""

    host = config[CONF_HOST]
    mac_address = config[CONF_MAC]
    device_name = config.get(CONF_NAME)

    if not hass.data.get(DATA_RSN):
        hass.data[DATA_RSN] = RSNetwork()
        job = hass.data[DATA_RSN].create_datagram_endpoint()
        hass.async_create_task(job)

    device = hass.data[DATA_RSN].register_device(mac_address, host)
    async_add_entities([RecSwitchSwitch(device, device_name, mac_address)])
コード例 #3
0
ファイル: client.py プロジェクト: squix78/pyrecswitch
        ret = await device.set_gpio_status(not ret.state)
        print('SET GPIO STATUS: flag={0.flag} state={0.state}'.format(ret))

        await asyncio.sleep(interval)

        # set relay status to initial value
        ret = await device.set_gpio_status(not ret.state)
        print('SET GPIO STATUS: flag={0.flag} state={0.state}'.format(ret))

    except RSNetworkError:
        print('network error occurred, sleep')


if __name__ == '__main__':

    if len(sys.argv) < 3:
        print('usage: {} ip-address mac-address'.format(sys.argv[0]))
        sys.exit(1)

    interval = 2
    remote_ip_address = sys.argv[1]
    remote_mac_address = sys.argv[2]
    loop = asyncio.get_event_loop()

    my_net = RSNetwork()
    listener = my_net.create_datagram_endpoint()
    transport, protocol = loop.run_until_complete(listener)
    my_device = my_net.register_device(remote_mac_address, remote_ip_address)

    loop.run_until_complete(polling(my_device))