Exemplo n.º 1
0
async def create_device(description_url: str) -> UpnpDevice:
    """Create UpnpDevice."""
    timeout = args.timeout
    requester = AiohttpRequester(timeout)
    non_strict = not args.strict
    factory = UpnpFactory(requester, non_strict=non_strict)
    return await factory.async_create_device(description_url)
Exemplo n.º 2
0
def create_control_point_from_settings():
    endpoint = notification_backend.AiohttpNotificationEndpoint(
        port=settings.EVENT_CALLBACK_PORT, public_ip=settings.PUBLIC_IP)
    notification = notification_backend.NotificationBackend(
        endpoint, AiohttpRequester())
    cp = AVControlPoint(notifcation_backend=notification)
    return cp
Exemplo n.º 3
0
async def create_device(description_url: str) -> UpnpDevice:
    """Create UpnpDevice."""
    timeout = args.timeout
    requester = AiohttpRequester(timeout)
    disable_validation = not args.strict
    factory = UpnpFactory(requester, disable_state_variable_validation=disable_validation)
    return await factory.async_create_device(description_url)
Exemplo n.º 4
0
 def __init__(self,
              device_registry: DeviceRegistry = None,
              notifcation_backend=None,
              device_factory: UpnpDeviceFactory = None):
     self._device_discover_observer = Observable[MediaDeviceDiscoveryEvent](
     )
     self._renderers: Dict[str, MediaRenderer] = {}
     self._servers: Dict[str, MediaServer] = {}
     if device_factory is None:
         self._upnp_device_factory = UpnpFactory(AiohttpRequester())
     else:
         self._upnp_device_factory = device_factory
     if device_registry is None:
         self._device_registry = DeviceRegistry()
     else:
         self._device_registry = device_registry
     self._device_registry.set_event_callback(self._handle_discovery_event)
     self._active_renderer = None
     if notifcation_backend is None:
         self._notify_receiver = NotificationBackend(
             AiohttpNotificationEndpoint(), AiohttpRequester())
     else:
         self._notify_receiver = notifcation_backend
Exemplo n.º 5
0
 def __init__(self, friendly_name, url, unique_id, timeout, defs):
     from async_upnp_client import UpnpFactory
     from async_upnp_client.aiohttp import AiohttpRequester
     """Initialize the remote."""
     self._name = friendly_name
     self._url = url
     self._unique_id = unique_id
     self._state = "off"
     self._device = None
     self._service = None
     self._states = dict.fromkeys(RCRemote.RC_STATES, -5)
     requester = AiohttpRequester(timeout)
     self._factory = UpnpFactory(requester, disable_unknown_out_argument_error=True)
     self._defaults = defs
Exemplo n.º 6
0
    async def find(self, config: Config) -> typing.List[Device]:
        devices = []
        requester = AiohttpRequester()
        factory = UpnpFactory(requester)
        source_ip = IPv4Address("0.0.0.0")

        async def on_response(data: typing.Mapping[str, typing.Any]) -> None:
            devices.append(await factory.async_create_device(data.get("LOCATION")))

        await async_search(service_type=_AVTRANSPORT_SCHEMA,
                           source_ip=source_ip,
                           timeout=config.upnp_scan_timeout,
                           async_callback=on_response)

        return [UpnpDevice(device, config, self._notify_handler) for device in devices]
Exemplo n.º 7
0
 async def init(self):
     requester = AiohttpRequester()
     factory = UpnpFactory(requester)
     self.device = await factory.async_create_device(self.location)
     self.product_service = self.device.service(
         "urn:av-openhome-org:service:Product:3")
     self.volume_service = self.device.service(
         "urn:av-openhome-org:service:Volume:4")
     self.transport_service = self.device.service(
         "urn:av-openhome-org:service:Transport:1")
     self.info_service = self.device.service(
         "urn:av-openhome-org:service:Info:1")
     self.pins_service = self.device.service(
         "urn:av-openhome-org:service:Pins:1")
     self.radio_service = self.device.service(
         "urn:av-openhome-org:service:Radio:1")
Exemplo n.º 8
0
    async def connect(self):
        requester = AiohttpRequester()
        factory = UpnpFactory(requester)
        device = await factory.async_create_device(self.url)

        self.service = device.service('urn:schemas-sony-com:service:Group:1')
        if not self.service:
            _LOGGER.error("Unable to find group service!")
            return False

        for act in self.service.actions.values():
            _LOGGER.debug("Action: %s (%s)", act,
                          [arg.name for arg in act.in_arguments()])

        return True
        """
Exemplo n.º 9
0
    async def check_device(self, dev):
        requester = AiohttpRequester()
        factory = UpnpFactory(requester)

        device = await factory.async_create_device(dev["LOCATION"])
        print(
            f"[+] Got device: {device.friendly_name} with {len(device.services)} services"
        )
        for name, service in device.services.items():
            if "WANIPConnection" in name or "WANPPPConnection" in name:
                print(
                    f"[+] Got wan*connection ({name}), checking for forwards.."
                )
                await self.check_forwards(service)
            else:
                print(f"[-] Got {name}")
Exemplo n.º 10
0
        async def parse_device(device):
            requester = AiohttpRequester()
            factory = UpnpFactory(requester)

            url = device["location"]
            try:
                device = await factory.async_create_device(url)
            except Exception as ex:
                _LOGGER.error(
                    "Unable to download the device description file from %s: %s",
                    url,
                    ex,
                )
                return

            if debug > 0:
                print(etree.ElementTree.tostring(device.xml).decode())

            NS = {"av": "urn:schemas-sony-com:av"}

            info = device.xml.find(".//av:X_ScalarWebAPI_DeviceInfo", NS)
            if not info:
                _LOGGER.error("Unable to find X_ScalaerWebAPI_DeviceInfo")
                return

            endpoint = info.find(".//av:X_ScalarWebAPI_BaseURL", NS).text
            version = info.find(".//av:X_ScalarWebAPI_Version", NS).text
            services = [
                x.text
                for x in info.findall(".//av:X_ScalarWebAPI_ServiceType", NS)
            ]

            dev = DiscoveredDevice(
                name=device.name,
                model_number=device.model_number,
                udn=device.udn,
                endpoint=endpoint,
                version=version,
                services=services,
                upnp_services=list(device.services.keys()),
                upnp_location=url,
            )

            _LOGGER.debug("Discovered: %s" % dev)

            if callback is not None:
                await callback(dev)
Exemplo n.º 11
0
async def main():
    # create the factory
    requester = AiohttpRequester()
    factory = UpnpFactory(requester)

    # create a device
    device = await factory.async_create_device(target)
    print("Device: {}".format(device))

    # get RenderingControle-service
    service = device.service("urn:schemas-upnp-org:service:RenderingControl:1")
    print("Service: {}".format(service))

    # perform GetVolume action
    get_volume = service.action("GetVolume")
    print("Action: {}".format(get_volume))
    result = await get_volume.async_call(InstanceID=0, Channel="Master")
    print("Action result: {}".format(result))
Exemplo n.º 12
0
async def async_main():
    """Asunc main."""
    if args.debug:
        _LOGGER.setLevel(logging.DEBUG)
        _LOGGER_LIB.setLevel(logging.DEBUG)
    if args.debug_traffic:
        _LOGGER_TRAFFIC.setLevel(logging.DEBUG)

    requester = AiohttpRequester()
    factory = UpnpFactory(requester)
    device = await factory.async_create_device(args.device)

    if hasattr(args, 'call-action'):
        await call_action(device, getattr(args, 'call-action'))
    elif hasattr(args, 'service'):
        await subscribe(device, args.service)
    else:
        parser.print_usage()
Exemplo n.º 13
0
    async def fetch_info(self):
        requester = AiohttpRequester()
        factory = UpnpFactory(requester)

        device = await factory.async_create_device(self.url)
        self.name = device.name
        # FIXME this depends currently on async_upnp_client internals..
        infodict = device.device_info._asdict()
        _LOGGER.debug("Got device info: %s from url %s", infodict, self.url)

        # we need to replace USN with udn from the XML.
        if self.udn != device.udn:
            _LOGGER.warning("Got different UDN, replacing..")
            self.udn = device.udn

        self.info = {k: v for k, v in infodict.items() if k != "xml"}
        self.info["icon"] = self.icon

        self.icons: List[Icon] = parse_icons(self.info["url"], device)
Exemplo n.º 14
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.º 15
0
    async def _get_upnp_services(self):
        requester = AiohttpRequester()
        factory = UpnpFactory(requester)

        if self._upnp_device is None:
            self._upnp_device = await factory.async_create_device(
                self._upnp_discovery.upnp_location)

        if self._upnp_renderer is None:
            media_renderers = await DmrDevice.async_search(timeout=1)
            host = urlparse(self.endpoint).hostname
            media_renderer_location = next(
                (r["location"] for r in media_renderers
                 if urlparse(r["location"]).hostname == host),
                None,
            )
            if media_renderer_location is None:
                raise SongpalException("Could not find UPnP media renderer")

            self._upnp_renderer = await factory.async_create_device(
                media_renderer_location)
Exemplo n.º 16
0
 def __init__(self, friendly_name, url, unique_id, timeout):
     from async_upnp_client import UpnpFactory
     from async_upnp_client.aiohttp import AiohttpRequester
     """Initialize the remote."""
     self._name = friendly_name
     self._url = url
     self._unique_id = unique_id
     self._state = "off"
     self._device = None
     self._service = None
     self._states = dict.fromkeys(MainTVAgent2Remote.STATES, '-5')
     requester = AiohttpRequester(timeout)
     self._factory = UpnpFactory(requester,
                                 disable_unknown_out_argument_error=True)
     self._sources = []
     self._channels = {}
     self._channel_list_type = None
     self._channel_satellite_id = None
     self._current_source = ''
     self._current_source_t = 0
     self._current_channel_t = 0
     self._current_source_l_t = 0
     self._current_channel_l_t = 0