예제 #1
0
def async_setup_platform(hass,
                         config,
                         async_add_entities,
                         discovery_info=None):
    """Set up home assistant scene entries."""
    # from aiopvapi.hub import Hub
    from aiopvapi.scenes import Scenes
    from aiopvapi.rooms import Rooms
    from aiopvapi.resources.scene import Scene as PvScene

    hub_address = config.get(HUB_ADDRESS)
    websession = async_get_clientsession(hass)

    _scenes = yield from Scenes(hub_address, hass.loop,
                                websession).get_resources()
    _rooms = yield from Rooms(hub_address, hass.loop,
                              websession).get_resources()

    if not _scenes or not _rooms:
        _LOGGER.error("Unable to initialize PowerView hub: %s", hub_address)
        return
    pvscenes = (PowerViewScene(
        hass, PvScene(_raw_scene, hub_address, hass.loop, websession), _rooms)
                for _raw_scene in _scenes[SCENE_DATA])
    async_add_entities(pvscenes)
 def __init__(self, hub_ip, loop_, session):
     self.request = AioRequest(hub_ip, loop=loop_, websession=session)
     self._scenes_entry_point = Scenes(self.request)
     self._rooms_entry_point = Rooms(self.request)
     self._shades_entry_point = Shades(self.request)
     self._scene_members_entry_point = SceneMembers(self.request)
     self.scenes = []  # A list of scene instances
     self.shades = []  # A list of shade instances
     self.rooms = []  # A list of room instances
예제 #3
0
파일: __init__.py 프로젝트: jbouwh/core
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
    """Set up Hunter Douglas PowerView from a config entry."""

    config = entry.data

    hub_address = config[CONF_HOST]
    websession = async_get_clientsession(hass)

    pv_request = AioRequest(hub_address, loop=hass.loop, websession=websession)

    try:
        async with async_timeout.timeout(10):
            device_info = await async_get_device_info(pv_request, hub_address)

        async with async_timeout.timeout(10):
            rooms = Rooms(pv_request)
            room_data = async_map_data_by_id(
                (await rooms.get_resources())[ROOM_DATA])

        async with async_timeout.timeout(10):
            scenes = Scenes(pv_request)
            scene_data = async_map_data_by_id(
                (await scenes.get_resources())[SCENE_DATA])

        async with async_timeout.timeout(10):
            shades = Shades(pv_request)
            shade_entries = await shades.get_resources()
            shade_data = async_map_data_by_id(shade_entries[SHADE_DATA])

    except HUB_EXCEPTIONS as err:
        raise ConfigEntryNotReady(
            f"Connection error to PowerView hub: {hub_address}: {err}"
        ) from err
    if not device_info:
        raise ConfigEntryNotReady(
            f"Unable to initialize PowerView hub: {hub_address}")

    coordinator = PowerviewShadeUpdateCoordinator(hass, shades, hub_address)
    coordinator.async_set_updated_data(PowerviewShadeData())
    # populate raw shade data into the coordinator for diagnostics
    coordinator.data.store_group_data(shade_entries[SHADE_DATA])

    hass.data.setdefault(DOMAIN, {})[entry.entry_id] = PowerviewEntryData(
        api=pv_request,
        room_data=room_data,
        scene_data=scene_data,
        shade_data=shade_data,
        coordinator=coordinator,
        device_info=device_info,
    )

    await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

    return True
예제 #4
0
    def __init__(self, hub_ip, _loop, session):
        self._connection_data = {
            ATTR_HUB_IP: hub_ip,
            ATTR_LOOP: _loop,
            ATTR_WEB_SESSION: session
        }

        self._rooms = Rooms(hub_ip, _loop, session)
        self._shades = Shades(hub_ip, _loop, session)
        self._scenes = Scenes(hub_ip, _loop, session)
        self._scene_members = SceneMembers(hub_ip, _loop, session)
예제 #5
0
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
    """Set up Hunter Douglas PowerView from a config entry."""

    config = entry.data

    hub_address = config[CONF_HOST]
    websession = async_get_clientsession(hass)

    pv_request = AioRequest(hub_address, loop=hass.loop, websession=websession)

    try:
        async with async_timeout.timeout(10):
            device_info = await async_get_device_info(pv_request)
            device_info[PV_HUB_ADDRESS] = hub_address

        async with async_timeout.timeout(10):
            rooms = Rooms(pv_request)
            room_data = async_map_data_by_id(
                (await rooms.get_resources())[ROOM_DATA])

        async with async_timeout.timeout(10):
            scenes = Scenes(pv_request)
            scene_data = async_map_data_by_id(
                (await scenes.get_resources())[SCENE_DATA])

        async with async_timeout.timeout(10):
            shades = Shades(pv_request)
            shade_data = async_map_data_by_id(
                (await shades.get_resources())[SHADE_DATA])
    except HUB_EXCEPTIONS as err:
        raise ConfigEntryNotReady(
            f"Connection error to PowerView hub: {hub_address}: {err}"
        ) from err
    if not device_info:
        raise ConfigEntryNotReady(
            f"Unable to initialize PowerView hub: {hub_address}")

    coordinator = PowerviewShadeUpdateCoordinator(hass, shades, hub_address)
    coordinator.async_set_updated_data(PowerviewShadeData())

    hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {
        PV_API: pv_request,
        PV_ROOM_DATA: room_data,
        PV_SCENE_DATA: scene_data,
        PV_SHADES: shades,
        PV_SHADE_DATA: shade_data,
        COORDINATOR: coordinator,
        DEVICE_INFO: device_info,
    }

    hass.config_entries.async_setup_platforms(entry, PLATFORMS)

    return True
예제 #6
0
파일: __init__.py 프로젝트: tpaulus/core
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
    """Set up Hunter Douglas PowerView from a config entry."""

    config = entry.data

    hub_address = config.get(CONF_HOST)
    websession = async_get_clientsession(hass)

    pv_request = AioRequest(hub_address, loop=hass.loop, websession=websession)

    try:
        async with async_timeout.timeout(10):
            device_info = await async_get_device_info(pv_request)

        async with async_timeout.timeout(10):
            rooms = Rooms(pv_request)
            room_data = _async_map_data_by_id(
                (await rooms.get_resources())[ROOM_DATA])

        async with async_timeout.timeout(10):
            scenes = Scenes(pv_request)
            scene_data = _async_map_data_by_id(
                (await scenes.get_resources())[SCENE_DATA])

        async with async_timeout.timeout(10):
            shades = Shades(pv_request)
            shade_data = _async_map_data_by_id(
                (await shades.get_resources())[SHADE_DATA])
    except HUB_EXCEPTIONS as err:
        _LOGGER.error("Connection error to PowerView hub: %s", hub_address)
        raise ConfigEntryNotReady from err

    if not device_info:
        _LOGGER.error("Unable to initialize PowerView hub: %s", hub_address)
        raise ConfigEntryNotReady

    async def async_update_data():
        """Fetch data from shade endpoint."""
        async with async_timeout.timeout(10):
            shade_entries = await shades.get_resources()
        if not shade_entries:
            raise UpdateFailed("Failed to fetch new shade data.")
        return _async_map_data_by_id(shade_entries[SHADE_DATA])

    coordinator = DataUpdateCoordinator(
        hass,
        _LOGGER,
        name="powerview hub",
        update_method=async_update_data,
        update_interval=timedelta(seconds=60),
    )

    hass.data.setdefault(DOMAIN, {})
    hass.data[DOMAIN][entry.entry_id] = {
        PV_API: pv_request,
        PV_ROOM_DATA: room_data,
        PV_SCENE_DATA: scene_data,
        PV_SHADES: shades,
        PV_SHADE_DATA: shade_data,
        COORDINATOR: coordinator,
        DEVICE_INFO: device_info,
    }

    hass.config_entries.async_setup_platforms(entry, PLATFORMS)

    return True
예제 #7
0
 async def go():
     await self.start_fake_server()
     scenes = Scenes(self.request)
     response = await scenes.get_instance(43436)
     return response
예제 #8
0
 async def go():
     await self.start_fake_server()
     scenes = Scenes(self.request)
     res = await scenes.create_scene(
         12372, 'New scene', color_id=1, icon_id=2)
     return res
예제 #9
0
 async def go():
     await self.start_fake_server()
     scenes = Scenes(self.request)
     res = await scenes.get_resources()
     return res
예제 #10
0
 def setup(self, ip_address):
     loop = asyncio.get_event_loop()
     session = aiohttp.ClientSession(loop=loop)
     self._shades = Shades(ip_address, loop, session)
     self._rooms = Rooms(ip_address, loop, session)
     self._scenes = Scenes(ip_address, loop, session)