def __init__(self, zwave_config_path, zwave_user_path, zwave_device="/dev/ttyACM0", qth_base_path="sys/zwave/", host=None, port=None, keepalive=10, loop=None): self._loop = loop or asyncio.get_event_loop() self._qth_base_path = qth_base_path self._client = qth.Client("qth_zwave", "Exposes Z-wave devices via Qth.", loop=self._loop, host=host, port=port, keepalive=keepalive) # Setup the OpenZWave client self._init_openzwave(zwave_device, zwave_config_path, zwave_user_path) # Setup the Qth mirror of the ZWave state self._network = Network(self._client, self._loop, self._ozw_network, self._qth_base_path) self._loop.create_task(self._network.init_async()) self._init_zwave_callbacks() self._ozw_network.start()
def main(): parser = ArgumentParser( description="Control a Panasonic VIERA TV") parser.add_argument("tv_hostname", help="IP or Hostname of TV to control") parser.add_argument("qth_path_prefix", help="Qth path prefix.") parser.add_argument("--update-interval", "-i", default=1.0, type=float, help="Update interval for power state in seconds. " "(default %(default)s).") parser.add_argument("--host", "-H", default=None, help="Qth server hostname.") parser.add_argument("--port", "-P", default=None, type=int, help="Qth server port.") parser.add_argument("--keepalive", "-K", default=10, type=int, help="MQTT Keepalive interval (seconds).") parser.add_argument("--version", "-V", action="version", version="%(prog)s {}".format(__version__)) args = parser.parse_args() client = qth.Client( "qth_panasonic_viera", "Panasonic VIERA TV control.", loop=loop, host=args.host, port=args.port, keepalive=args.keepalive, ) tv = panasonic_viera.RemoteControl(args.tv_hostname) loop.run_until_complete(async_main(client, tv, args.qth_path_prefix, args.update_interval)) loop.run_forever()
async def connect_to_qth(loop, qth_host, qth_port): """ Connect to Qth. Returns the Qth Client object. """ return qth.Client("qth_postgres_log", loop=loop, host=qth_host, port=qth_port)
def get_default_qth_client(): """ Get the default :py:class:`qth.Client` object. One will be created with the name ``qth_yarp_based_client`` if no client has been provided by :py:func:`set_default_client`. """ global _default_client if _default_client is None: _default_client = qth.Client("qth_yarp_based_client", "A qth_yarp based client.") return _default_client
def __init__(self, cache_file="/dev/null", prefix="meta/alias/", host=None, port=None, keepalive=10, loop=None): """ Initialise the Qth Alias server. Call async_init() soon after construciton. Parameters ---------- cache_file : str Filename into which the current set of aliases is saved and loaded. prefix : str The prefix for the Qth paths which control the alias server. host : str or None Qth hostname. port : int or None Qth port. keepalive : int MQTT Keepalive interval. loop : qsyncio.AbstractEventLoop The event loop to use. """ self._cache_file = cache_file self._loop = loop or asyncio.get_event_loop() self._add_path = prefix + "add" self._remove_path = prefix + "remove" self._aliases_path = prefix + "aliases" self._error_path = prefix + "error" self._client = qth.Client( "qth_alias", "Defines aliases of Qth properties and events.", host=host, port=port, keepalive=keepalive, loop=self._loop) self._ls = Ls(self._client, self._loop) # Lock to hold while self._aliases is being updated. self._aliases_lock = asyncio.Lock(loop=self._loop) # The current set of alias registrations. # {"path/to/alias": Alias, ...} self._aliases = {}
def __init__(self, loop, qth_prefix="network/", qth_host=None, qth_port=None, qth_keepalive=10, openwrt_host="http://router/", openwrt_wan_interface="pppoa-wan", update_rate=5.0): self.loop = loop self.qth_wifi_hosts_path = "{}wifi/hosts".format(qth_prefix) self.qth_up_rate_path = "{}internet/up".format(qth_prefix) self.qth_up_data_used_path = "{}internet/up/data-used".format(qth_prefix) self.qth_down_rate_path = "{}internet/down".format(qth_prefix) self.qth_down_data_used_path = "{}internet/down/data-used".format(qth_prefix) self.qth_connections_path = "{}internet/connections".format(qth_prefix) self.openwrt_host = openwrt_host self.openwrt_wan_interface = openwrt_wan_interface self.update_rate = update_rate self.qth_client = qth.Client("qth_openwrt_status", "Monitors connections to a OpenWRT router.", host=qth_host, port=qth_port, keepalive=qth_keepalive, loop=self.loop) self.arp_lookup = ARPLookup(self.loop, "{}proc_net_arp".format(self.openwrt_host)) self.dns_lookup = ReverseDNSLookup(self.loop) self.wifi_client_status = WifiClientStatus( self.loop, "{}iwinfo".format(self.openwrt_host), self.arp_lookup, self.dns_lookup) self.interface_status = InterfaceStatus( self.loop, "{}proc_net_dev".format(self.openwrt_host), openwrt_wan_interface) self.nat_connection_status = NATConnectionStatus( self.loop, "{}proc_net_nf_conntrack".format(self.openwrt_host), self.dns_lookup) self.loop.run_until_complete(self.run())
def main(): parser = ArgumentParser( description="Control Chromecast devices on the local network") parser.add_argument("--qth-path-prefix", "-p", default="sys/chromecast/", help="Qth path prefix.") parser.add_argument("--host", "-H", default=None, help="Qth server hostname.") parser.add_argument("--port", "-P", default=None, type=int, help="Qth server port.") parser.add_argument("--keepalive", "-K", default=10, type=int, help="MQTT Keepalive interval (seconds).") parser.add_argument("--version", "-V", action="version", version="%(prog)s {}".format(__version__)) args = parser.parse_args() client = qth.Client( "qth_chromecast", "Chromecast control", loop=loop, host=args.host, port=args.port, keepalive=args.keepalive, ) qth_cc = QthChromecast(loop, client, args.qth_path_prefix) loop.run_forever()
def main(): parser = ArgumentParser( description="A service which reports weather forecasts from Darksky") parser.add_argument("apikey", help="Darksky.net API key") parser.add_argument("latitude", type=float, help="Latitude of forecast location.") parser.add_argument("longitude", type=float, help="Longitude of forecast location.") parser.add_argument("--prefix", "-p", default="weather/", help="Prefix for all weather reporting properties " "(default %(default)s).") parser.add_argument("--units", "-u", default="auto", choices=["auto", "ca", "uk2", "windGust", "us", "si"], help="Darksky.net unit type choice. " "(default %(default)s).") parser.add_argument("--update-interval", "-i", default=900, type=float, help="Update interval in seconds. " "(default %(default)s).") parser.add_argument("--host", "-H", default=None, help="Qth server hostname.") parser.add_argument("--port", "-P", default=None, type=int, help="Qth server port.") parser.add_argument("--keepalive", "-K", default=10, type=int, help="MQTT Keepalive interval (seconds).") parser.add_argument("--version", "-V", action="version", version="%(prog)s {}".format(__version__)) args = parser.parse_args() global client, prefix, api_key, longitude, latitude, units, interval client = qth.Client( "qth_darksky", "Weather forecasts for Qth from Darksky.net", loop=loop, host=args.host, port=args.port, keepalive=args.keepalive, ) prefix = args.prefix api_key = args.apikey latitude = args.latitude longitude = args.longitude units = args.units interval = args.update_interval loop.run_until_complete(async_main()) try: loop.run_forever() except KeyboardInterrupt: # Don't crash on Ctrl+C pass