Exemplo n.º 1
0
    async def found_device(self, upnp_device):
        if self.device:
            self.logger.error("Device exists already, do not create a new one")
            return

        self.upnp_device = upnp_device
        # build upnp/aiohttp requester
        session = aiohttp.ClientSession()
        requester = AiohttpSessionRequester(session, True)
        # ensure event handler has been started
        server_host = await async_get_local_ip()
        if server_host:
            server_host = server_host[1]
        else:
            self.logger.error(f"Failed to add device {self.device}")
        server_port = DEFAULT_LISTEN_PORT
        event_handler = await self.async_start_event_handler(
            server_host, server_port, requester
        )

        # wrap with DmrDevice
        dlna_device = DmrDevice(self.upnp_device, event_handler)

        # create our own device
        self.device = DlnaDmrDevice(self, dlna_device)
        self.logger.debug("Adding device: %s", self.device)

        await self.updateDeviceReadings()
        await fhem.readingsSingleUpdate(self.hash, "state", "online", 1)
        self.update_task = self.create_async_task(self.update())
Exemplo n.º 2
0
async def async_create_upnp_device(hass: HomeAssistant,
                                   ssdp_location: str) -> UpnpDevice:
    """Create UPnP device."""
    session = async_get_clientsession(hass)
    requester = AiohttpSessionRequester(session, with_sleep=True, timeout=20)

    factory = UpnpFactory(requester, disable_state_variable_validation=True)
    return await factory.async_create_device(ssdp_location)
Exemplo n.º 3
0
 def __init__(self, hass: HomeAssistant) -> None:
     """Initialize global data."""
     self.lock = asyncio.Lock()
     session = aiohttp_client.async_get_clientsession(hass,
                                                      verify_ssl=False)
     self.requester = AiohttpSessionRequester(session, with_sleep=True)
     self.upnp_factory = UpnpFactory(self.requester, non_strict=True)
     self.event_notifiers = {}
     self.event_notifier_refs = defaultdict(int)
Exemplo n.º 4
0
    async def async_create_upnp_device(cls, hass: HomeAssistant,
                                       ssdp_location: str) -> UpnpDevice:
        """Create UPnP device."""
        # Build async_upnp_client requester.
        session = async_get_clientsession(hass)
        requester = AiohttpSessionRequester(session, True, 10)

        # Create async_upnp_client device.
        factory = UpnpFactory(requester,
                              disable_state_variable_validation=True)
        return await factory.async_create_device(ssdp_location)
Exemplo n.º 5
0
 def __init__(
     self,
     hass: HomeAssistant,
 ) -> None:
     """Initialize global data."""
     self.hass = hass
     session = aiohttp_client.async_get_clientsession(hass, verify_ssl=False)
     self.requester = AiohttpSessionRequester(session, with_sleep=True)
     self.upnp_factory = UpnpFactory(self.requester, non_strict=True)
     self.devices = {}
     self.sources = {}
Exemplo n.º 6
0
async def async_setup_platform(hass: HomeAssistantType,
                               config,
                               async_add_entities,
                               discovery_info=None):
    """Set up DLNA DMR platform."""
    if config.get(CONF_URL) is not None:
        url = config[CONF_URL]
        name = config.get(CONF_NAME)
    elif discovery_info is not None:
        url = discovery_info["ssdp_description"]
        name = discovery_info.get("name")

    if DLNA_DMR_DATA not in hass.data:
        hass.data[DLNA_DMR_DATA] = {}

    if "lock" not in hass.data[DLNA_DMR_DATA]:
        hass.data[DLNA_DMR_DATA]["lock"] = asyncio.Lock()

    # build upnp/aiohttp requester
    from async_upnp_client.aiohttp import AiohttpSessionRequester

    session = async_get_clientsession(hass)
    requester = AiohttpSessionRequester(session, True)

    # ensure event handler has been started
    with await hass.data[DLNA_DMR_DATA]["lock"]:
        server_host = config.get(CONF_LISTEN_IP)
        if server_host is None:
            server_host = get_local_ip()
        server_port = config.get(CONF_LISTEN_PORT, DEFAULT_LISTEN_PORT)
        callback_url_override = config.get(CONF_CALLBACK_URL_OVERRIDE)
        event_handler = await async_start_event_handler(
            hass, server_host, server_port, requester, callback_url_override)

    # create upnp device
    from async_upnp_client import UpnpFactory

    factory = UpnpFactory(requester, disable_state_variable_validation=True)
    try:
        upnp_device = await factory.async_create_device(url)
    except (asyncio.TimeoutError, aiohttp.ClientError):
        raise PlatformNotReady()

    # wrap with DmrDevice
    from async_upnp_client.profiles.dlna import DmrDevice

    dlna_device = DmrDevice(upnp_device, event_handler)

    # create our own device
    device = DlnaDmrDevice(dlna_device, name)
    _LOGGER.debug("Adding device: %s", device)
    async_add_entities([device], True)
Exemplo n.º 7
0
    async def async_create_device(cls, hass: HomeAssistantType, ssdp_description: str):
        """Create UPnP/IGD device."""
        # build async_upnp_client requester
        session = async_get_clientsession(hass)
        requester = AiohttpSessionRequester(session, True)

        # create async_upnp_client device
        factory = UpnpFactory(requester, disable_state_variable_validation=True)
        upnp_device = await factory.async_create_device(ssdp_description)

        igd_device = IgdDevice(upnp_device, None)

        return cls(igd_device)
Exemplo n.º 8
0
async def async_create_device(hass: HomeAssistant,
                              ssdp_location: str) -> Device:
    """Create UPnP/IGD device."""
    session = async_get_clientsession(hass, verify_ssl=False)
    requester = AiohttpSessionRequester(session, with_sleep=True, timeout=20)

    factory = UpnpFactory(requester, disable_state_variable_validation=True)
    upnp_device = await factory.async_create_device(ssdp_location)

    # Create profile wrapper.
    igd_device = IgdDevice(upnp_device, None)
    device = Device(hass, igd_device)

    return device
Exemplo n.º 9
0
    async def async_start(self) -> None:
        """Start the scanners."""
        session = async_get_clientsession(self.hass)
        requester = AiohttpSessionRequester(session, True, 10)
        self._description_cache = DescriptionCache(requester)

        await self._async_start_ssdp_listeners()

        self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.async_stop)
        self._cancel_scan = async_track_time_interval(
            self.hass, self.async_scan, SCAN_INTERVAL
        )

        # Trigger the initial-scan.
        await self.async_scan()
Exemplo n.º 10
0
    def __init__(self, logger):
        if ssdp.__instance is not None:
            raise Exception("ssdp already defined, use getInstance")
        self.logger = logger
        self.listeners = []
        self.listener = None
        self.search_task = None
        self.advertisement_task = None
        self.nr_started_searches = 0

        # build upnp/aiohttp requester
        self.session = aiohttp.ClientSession()
        self.requester = AiohttpSessionRequester(self.session, True)
        # create upnp device
        self.factory = UpnpFactory(self.requester)
Exemplo n.º 11
0
 def __init__(
     self,
     hass: HomeAssistant,
 ) -> None:
     """Initialize global data."""
     self.hass = hass
     self.lock = asyncio.Lock()
     session = aiohttp_client.async_get_clientsession(hass,
                                                      verify_ssl=False)
     self.requester = AiohttpSessionRequester(session, with_sleep=True)
     self.upnp_factory = UpnpFactory(self.requester, non_strict=True)
     # NOTE: event_handler is not actually used, and is only created to
     # satisfy the DmsDevice.__init__ signature
     self.event_handler = UpnpEventHandler("", self.requester)
     self.devices = {}
     self.sources = {}
Exemplo n.º 12
0
async def get_dlna_action(location,
                          service,
                          action,
                          http_headers=None,
                          session=None):
    """Return DLNA action pased on passed parameters"""
    if session:
        requester = AiohttpSessionRequester(timeout=TIMEOUT_UPNP,
                                            http_headers=http_headers,
                                            session=session)
    else:
        requester = AiohttpRequester(timeout=TIMEOUT_UPNP,
                                     http_headers=http_headers)

    factory = UpnpFactory(requester)
    device = await factory.async_create_device(location)
    service = device.service(service)
    action = service.action(action)
    return action
Exemplo n.º 13
0
    async def async_create_device(
        cls, hass: HomeAssistant, ssdp_location: str
    ) -> Device:
        """Create UPnP/IGD device."""
        # Build async_upnp_client requester.
        session = async_get_clientsession(hass)
        requester = AiohttpSessionRequester(session, True, 10)

        # Create async_upnp_client device.
        factory = UpnpFactory(requester, disable_state_variable_validation=True)
        upnp_device = await factory.async_create_device(ssdp_location)

        # Create profile wrapper.
        igd_device = IgdDevice(upnp_device, None)

        # Create updater.
        local_ip = _get_local_ip(hass)
        device_updater = DeviceUpdater(
            device=upnp_device, factory=factory, source_ip=local_ip
        )

        return cls(igd_device, device_updater)
Exemplo n.º 14
0
async def async_get_model_name(session, location):
    """Return model name."""
    requester = AiohttpSessionRequester(timeout=TIMEOUT_UPNP, session=session)
    factory = UpnpFactory(requester)
    device = await factory.async_create_device(location)
    return device.model_name