desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Disconnect client.'
| def close(self):
| with self._lock:
self._client.close()
|
'Connect client.'
| def connect(self):
| with self._lock:
self._client.connect()
|
'Read coils.'
| def read_coils(self, unit, address, count):
| with self._lock:
kwargs = ({'unit': unit} if unit else {})
return self._client.read_coils(address, count, **kwargs)
|
'Read input registers.'
| def read_input_registers(self, unit, address, count):
| with self._lock:
kwargs = ({'unit': unit} if unit else {})
return self._client.read_input_registers(address, count, **kwargs)
|
'Read holding registers.'
| def read_holding_registers(self, unit, address, count):
| with self._lock:
kwargs = ({'unit': unit} if unit else {})
return self._client.read_holding_registers(address, count, **kwargs)
|
'Write coil.'
| def write_coil(self, unit, address, value):
| with self._lock:
kwargs = ({'unit': unit} if unit else {})
self._client.write_coil(address, value, **kwargs)
|
'Write register.'
| def write_register(self, unit, address, value):
| with self._lock:
kwargs = ({'unit': unit} if unit else {})
self._client.write_register(address, value, **kwargs)
|
'Write registers.'
| def write_registers(self, unit, address, values):
| with self._lock:
kwargs = ({'unit': unit} if unit else {})
self._client.write_registers(address, values, **kwargs)
|
'Retrieve groups of node.'
| @ha.callback
def get(self, request, node_id):
| nodeid = int(node_id)
hass = request.app['hass']
values_list = hass.data[const.DATA_ENTITY_VALUES]
values_data = {}
for entity_values in values_list:
if (entity_values.primary.node.node_id != nodeid):
continue
values_data[entity_values.primary.value_id] = {'label': entity... |
'Retrieve groups of node.'
| @ha.callback
def get(self, request, node_id):
| nodeid = int(node_id)
hass = request.app['hass']
network = hass.data.get(const.DATA_NETWORK)
node = network.nodes.get(nodeid)
if (node is None):
return self.json_message('Node not found', HTTP_NOT_FOUND)
groupdata = node.groups
groups = {}
for (key, value) in groupdata.item... |
'Retrieve configurations of node.'
| @ha.callback
def get(self, request, node_id):
| nodeid = int(node_id)
hass = request.app['hass']
network = hass.data.get(const.DATA_NETWORK)
node = network.nodes.get(nodeid)
if (node is None):
return self.json_message('Node not found', HTTP_NOT_FOUND)
config = {}
for value in node.get_values(class_id=const.COMMAND_CLASS_CONF... |
'Retrieve usercodes of node.'
| @ha.callback
def get(self, request, node_id):
| nodeid = int(node_id)
hass = request.app['hass']
network = hass.data.get(const.DATA_NETWORK)
node = network.nodes.get(nodeid)
if (node is None):
return self.json_message('Node not found', HTTP_NOT_FOUND)
usercodes = {}
if (not node.has_command_class(const.COMMAND_CLASS_USER_COD... |
'Initialize the BookSky.'
| def __init__(self, api_key):
| self._api_key = api_key
self.devices = {}
_LOGGER.debug('Initial BloomSky device load...')
self.refresh_devices()
|
'Use the API to retrieve a list of devices.'
| @Throttle(MIN_TIME_BETWEEN_UPDATES)
def refresh_devices(self):
| _LOGGER.debug('Fetching BloomSky update')
response = requests.get(self.API_URL, headers={'Authorization': self._api_key}, timeout=10)
if (response.status_code == 401):
raise RuntimeError('Invalid API_KEY')
elif (response.status_code != 200):
_LOGGER.error('Invalid HTTP res... |
'Initialize the service.'
| def __init__(self, config):
| self.username = config.get(CONF_USERNAME)
self.api_key = config.get(CONF_API_KEY)
self.recipient = config.get(CONF_RECIPIENT)
|
'Send a message to a user.'
| def send_message(self, message='', **kwargs):
| data = {'messages': [{'source': 'hass.notify', 'from': self.recipient, 'to': self.recipient, 'body': message}]}
api_url = '{}/sms/send'.format(BASE_API_URL)
resp = requests.post(api_url, data=json.dumps(data), headers=HEADERS, auth=(self.username, self.api_key), timeout=5)
obj = json.loads(resp.text)
... |
'Initialize the service.'
| def __init__(self, thermostat_index):
| self.thermostat_index = thermostat_index
|
'Send a message to a command line.'
| def send_message(self, message='', **kwargs):
| ecobee.NETWORK.ecobee.send_message(self.thermostat_index, message)
|
'Initialize the service.'
| def __init__(self, token, default_room):
| from ciscosparkapi import CiscoSparkAPI
self._default_room = default_room
self._token = token
self._spark = CiscoSparkAPI(access_token=self._token)
|
'Send a message to a user.'
| def send_message(self, message='', **kwargs):
| from ciscosparkapi import SparkApiError
try:
title = ''
if (kwargs.get(ATTR_TITLE) is not None):
title = (kwargs.get(ATTR_TITLE) + ': ')
self._spark.messages.create(roomId=self._default_room, text=(title + message))
except SparkApiError as api_error:
_LOGGER.er... |
'Initialize the service.'
| def __init__(self, lambda_client, context):
| self.client = lambda_client
self.context = context
|
'Send notification to specified LAMBDA ARN.'
| def send_message(self, message='', **kwargs):
| targets = kwargs.get(ATTR_TARGET)
if (not targets):
_LOGGER.info('At least 1 target is required')
return
for target in targets:
cleaned_kwargs = dict(((k, v) for (k, v) in kwargs.items() if v))
payload = {'message': message}
payload.update(cleaned_kwarg... |
'Initialize the service.'
| def __init__(self, username, access_token):
| from freesms import FreeClient
self.free_client = FreeClient(username, access_token)
|
'Send a message to the Free Mobile user cell.'
| def send_message(self, message='', **kwargs):
| resp = self.free_client.send_sms(message)
if (resp.status_code == 400):
_LOGGER.error('At least one parameter is missing')
elif (resp.status_code == 402):
_LOGGER.error('Too much SMS send in a few time')
elif (resp.status_code == 403):
_LOGGER.... |
'Initialize the service.'
| def __init__(self, hass, host, port):
| self._hass = hass
self._host = host
self._port = port
|
'Send a message to Lannouncer.'
| def send_message(self, message='', **kwargs):
| data = kwargs.get(ATTR_DATA)
if ((data is not None) and (ATTR_METHOD in data)):
method = data.get(ATTR_METHOD)
else:
method = ATTR_METHOD_DEFAULT
if (method not in ATTR_METHOD_ALLOWED):
_LOGGER.error('Unknown method %s', method)
return
cmd = urlencode({method: m... |
'Send a message.'
| def send_msg(self, msg):
| for sub_msg in [msg[i:(i + 25)] for i in range(0, len(msg), 25)]:
self.gateway.set_child_value(self.node_id, self.child_id, self.value_type, sub_msg)
|
'Initialize the service.'
| def __init__(self, platform_devices):
| self.platform_devices = platform_devices
|
'Send a message to a user.'
| def send_message(self, message='', **kwargs):
| target_devices = kwargs.get(ATTR_TARGET)
devices = []
for gw_devs in self.platform_devices:
for device in gw_devs.values():
if ((target_devices is None) or (device.name in target_devices)):
devices.append(device)
for device in devices:
device.send_msg(message)... |
'Initialize the service.'
| def __init__(self, consumer_key, consumer_secret, phone_number):
| self._consumer_key = consumer_key
self._consumer_secret = consumer_secret
self._phone_number = phone_number
|
'Send a message to a user.'
| def send_message(self, message='', **kwargs):
| title = kwargs.get(ATTR_TITLE)
token_response = _authenticate(self._consumer_key, self._consumer_secret)
if (token_response is False):
_LOGGER.exception('Error obtaining authorization from Telstra API')
return
if title:
text = '{} {}'.format(title, message)
... |
'Initialize the service.'
| def __init__(self, secret, recipient, device=None):
| self._secret = secret
self._recipient = recipient
self._device = device
|
'Send a message to a user.'
| def send_message(self, message='', **kwargs):
| _LOGGER.debug('Sending to: %s, %s', self._recipient, str(self._device))
data = {'secret': self._secret, 'to': self._recipient, 'device': self._device, 'payload': message}
response = requests.post(_RESOURCE, json=data)
if (response.status_code != 200):
_LOGGER.error(('Error sending ... |
'Initialize the SMTP service.'
| def __init__(self, server, port, timeout, sender, encryption, username, password, recipients, sender_name, debug):
| self._server = server
self._port = port
self._timeout = timeout
self._sender = sender
self.encryption = encryption
self.username = username
self.password = password
self.recipients = recipients
self._sender_name = sender_name
self.debug = debug
self.tries = 2
|
'Connect/authenticate to SMTP Server.'
| def connect(self):
| if (self.encryption == 'tls'):
mail = smtplib.SMTP_SSL(self._server, self._port, timeout=self._timeout)
else:
mail = smtplib.SMTP(self._server, self._port, timeout=self._timeout)
mail.set_debuglevel(self.debug)
mail.ehlo_or_helo_if_needed()
if (self.encryption == 'starttls'):
... |
'Check for valid config, verify connectivity.'
| def connection_is_valid(self):
| server = None
try:
server = self.connect()
except smtplib.socket.gaierror:
_LOGGER.exception('SMTP server not found (%s:%s). Please check the IP address or hostname of your SMTP server', self._server, self._port)
return False
except (s... |
'Build and send a message to a user.
Will send plain text normally, or will build a multipart HTML message
with inline image attachments if images config is defined, or will
build a multipart HTML if html config is defined.'
| def send_message(self, message='', **kwargs):
| subject = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
data = kwargs.get(ATTR_DATA)
if data:
if (ATTR_HTML in data):
msg = _build_html_msg(message, data[ATTR_HTML], images=data.get(ATTR_IMAGES))
else:
msg = _build_multipart_msg(message, images=data.get(ATTR_IMAGES))
... |
'Send the message.'
| def _send_email(self, msg):
| mail = self.connect()
for _ in range(self.tries):
try:
mail.sendmail(self._sender, self.recipients, msg.as_string())
break
except smtplib.SMTPServerDisconnected:
_LOGGER.warning('SMTPServerDisconnected sending mail: retrying connection')
... |
'Initialize the service.'
| def __init__(self, api_key, device_id, device_ids, device_names):
| self._api_key = api_key
self._device_id = device_id
self._device_ids = device_ids
self._device_names = device_names
|
'Send a message to a user.'
| def send_message(self, message='', **kwargs):
| from pyjoin import send_notification
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
data = (kwargs.get(ATTR_DATA) or {})
send_notification(device_id=self._device_id, device_ids=self._device_ids, device_names=self._device_names, text=message, title=title, icon=data.get('icon'), smallicon=data.get('sm... |
'Initialize the service.'
| def __init__(self, hass, resource, method, message_param_name, title_param_name, target_param_name, data, data_template):
| self._resource = resource
self._hass = hass
self._method = method.upper()
self._message_param_name = message_param_name
self._title_param_name = title_param_name
self._target_param_name = target_param_name
self._data = data
self._data_template = data_template
|
'Send a message to a user.'
| def send_message(self, message='', **kwargs):
| data = {self._message_param_name: message}
if (self._title_param_name is not None):
data[self._title_param_name] = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
if ((self._target_param_name is not None) and (ATTR_TARGET in kwargs)):
data[self._target_param_name] = kwargs[ATTR_TARGET][0]
if ... |
'Initialize the service.'
| def __init__(self, domain, sandbox, api_key, sender, recipient):
| self._client = None
self._domain = domain
self._sandbox = sandbox
self._api_key = api_key
self._sender = sender
self._recipient = recipient
|
'Initialize the connection to Mailgun.'
| def initialize_client(self):
| from pymailgunner import Client
self._client = Client(self._api_key, self._domain, self._sandbox)
_LOGGER.debug('Mailgun domain: %s', self._client.domain)
self._domain = self._client.domain
if (not self._sender):
self._sender = DEFAULT_SENDER.format(domain=self._domain)
|
'Check whether the provided credentials are valid.'
| def connection_is_valid(self):
| from pymailgunner import MailgunCredentialsError, MailgunDomainError
try:
self.initialize_client()
except MailgunCredentialsError:
_LOGGER.exception('Invalid credentials')
return False
except MailgunDomainError as mailgun_error:
_LOGGER.exception(mailgun_error)
... |
'Send a mail to the recipient.'
| def send_message(self, message='', **kwargs):
| from pymailgunner import MailgunError
subject = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
data = kwargs.get(ATTR_DATA)
files = (data.get(ATTR_IMAGES) if data else None)
try:
if (self._client is None):
self.initialize_client()
resp = self._client.send_mail(sender=self._se... |
'Initialize the service.'
| def __init__(self, remoteip, duration, position, transparency, color, interrupt, timeout):
| self._target = 'http://{}:7676'.format(remoteip)
self._default_duration = duration
self._default_position = position
self._default_transparency = transparency
self._default_color = color
self._default_interrupt = interrupt
self._timeout = timeout
self._icon_file = os.path.join(os.path.di... |
'Send a message to a Android TV device.'
| def send_message(self, message='', **kwargs):
| _LOGGER.debug('Sending notification to: %s', self._target)
payload = dict(filename=('icon.png', open(self._icon_file, 'rb'), 'application/octet-stream', {'Expires': '0'}), type='0', title=kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT), msg=message, duration=('%i' % self._default_duration), position=('%i' %... |
'Initialize the service.'
| def __init__(self, sqs_client):
| self.client = sqs_client
|
'Send notification to specified SQS ARN.'
| def send_message(self, message='', **kwargs):
| targets = kwargs.get(ATTR_TARGET)
if (not targets):
_LOGGER.info('At least 1 target is required')
return
for target in targets:
cleaned_kwargs = dict(((k, v) for (k, v) in kwargs.items() if v))
message_body = {'message': message}
message_body.update(cle... |
'Initialize the service.'
| def __init__(self, pb):
| self.pushbullet = pb
self.pbtargets = {}
self.refresh()
|
'Refresh devices, contacts, etc.
pbtargets stores all targets available from this Pushbullet instance
into a dict. These are Pushbullet objects!. It sacrifices a bit of
memory for faster processing at send_message.
As of sept 2015, contacts were replaced by chats. This is not
implemented in the module yet.'
| def refresh(self):
| self.pushbullet.refresh()
self.pbtargets = {'device': {tgt.nickname.lower(): tgt for tgt in self.pushbullet.devices}, 'channel': {tgt.channel_tag.lower(): tgt for tgt in self.pushbullet.channels}}
|
'Send a message to a specified target.
If no target specified, a \'normal\' push will be sent to all devices
linked to the Pushbullet account.
Email is special, these are assumed to always exist. We use a special
call which doesn\'t require a push object.'
| def send_message(self, message=None, **kwargs):
| targets = kwargs.get(ATTR_TARGET)
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
data = kwargs.get(ATTR_DATA)
url = None
filepath = None
if data:
url = data.get(ATTR_URL, None)
filepath = data.get(ATTR_FILE, None)
refreshed = False
if (not targets):
if url:
... |
'Initialize the service.'
| def __init__(self, client, icon_path):
| self._client = client
self._icon_path = icon_path
|
'Send a message to the tv.'
| def send_message(self, message='', **kwargs):
| from pylgtv import PyLGTVPairException
try:
data = kwargs.get(ATTR_DATA)
icon_path = (data.get(CONF_ICON, self._icon_path) if data else self._icon_path)
self._client.send_message(message, icon_path=icon_path)
except PyLGTVPairException:
_LOGGER.error('Pairing with TV ... |
'Initialize the service.'
| def __init__(self, device_key):
| self._device_key = device_key
|
'Send a message to a user.'
| def send_message(self, message='', **kwargs):
| title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
response = requests.get('{}/{}/{}/{}'.format(_RESOURCE, self._device_key, title, message), timeout=DEFAULT_TIMEOUT)
if (response.json()['status'] != 'OK'):
_LOGGER.error('Not possible to send notification')
|
'Initialize the service.'
| def __init__(self, sender, password, recipient, tls):
| self._sender = sender
self._password = password
self._recipient = recipient
self._tls = tls
|
'Send a message to a user.'
| def send_message(self, message='', **kwargs):
| title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
data = ('{}: {}'.format(title, message) if title else message)
send_message('{}/home-assistant'.format(self._sender), self._password, self._recipient, self._tls, data)
|
'Initialize the service.'
| def __init__(self, command):
| self.command = command
|
'Send a message to a command line.'
| def send_message(self, message='', **kwargs):
| try:
proc = subprocess.Popen(self.command, universal_newlines=True, stdin=subprocess.PIPE, shell=True)
proc.communicate(input=message)
if (proc.returncode != 0):
_LOGGER.error('Command failed: %s', self.command)
except subprocess.SubprocessError:
_LOGGER.error('... |
'Initialize the service.'
| def __init__(self, app_name, app_icon, hostname, password, port):
| import gntp.notifier
import gntp.errors
self.gntp = gntp.notifier.GrowlNotifier(applicationName=app_name, notifications=['Notification'], applicationIcon=app_icon, hostname=hostname, password=password, port=port)
try:
self.gntp.register()
except gntp.errors.NetworkError:
_LOGGER.erro... |
'Send a message to a user.'
| def send_message(self, message='', **kwargs):
| self.gntp.notify(noteType='Notification', title=kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT), description=message)
|
'Initialize Apns Device.'
| def __init__(self, push_id, name, tracking_device_id=None, disabled=False):
| self.device_push_id = push_id
self.device_name = name
self.tracking_id = tracking_device_id
self.device_disabled = disabled
|
'Return the APNS id for the device.'
| @property
def push_id(self):
| return self.device_push_id
|
'Return the friendly name for the device.'
| @property
def name(self):
| return self.device_name
|
'Return the device Id.
The id of a device that is tracked by the device
tracking component.'
| @property
def tracking_device_id(self):
| return self.tracking_id
|
'Return the fully qualified device id.
The full id of a device that is tracked by the device
tracking component.'
| @property
def full_tracking_device_id(self):
| return '{}.{}'.format(DEVICE_TRACKER_DOMAIN, self.tracking_id)
|
'Return the .'
| @property
def disabled(self):
| return self.device_disabled
|
'Disable the device from recieving notifications.'
| def disable(self):
| self.device_disabled = True
|
'Return the comparision.'
| def __eq__(self, other):
| if isinstance(other, self.__class__):
return ((self.push_id == other.push_id) and (self.name == other.name))
return NotImplemented
|
'Return the comparision.'
| def __ne__(self, other):
| return (not self.__eq__(other))
|
'Initialize APNS application.'
| def __init__(self, hass, app_name, topic, sandbox, cert_file):
| self.hass = hass
self.app_name = app_name
self.sandbox = sandbox
self.certificate = cert_file
self.yaml_path = hass.config.path(((app_name + '_') + APNS_DEVICES))
self.devices = {}
self.device_states = {}
self.topic = topic
if os.path.isfile(self.yaml_path):
self.devices = {s... |
'Listen for sate change.
Track device state change if a device has a tracking id specified.'
| def device_state_changed_listener(self, entity_id, from_s, to_s):
| self.device_states[entity_id] = str(to_s.state)
|
'Write all known devices to file.'
| def write_devices(self):
| with open(self.yaml_path, 'w+') as out:
for (_, device) in self.devices.items():
_write_device(out, device)
|
'Register a device to receive push messages.'
| def register(self, call):
| push_id = call.data.get(ATTR_PUSH_ID)
device_name = call.data.get(ATTR_NAME)
current_device = self.devices.get(push_id)
current_tracking_id = (None if (current_device is None) else current_device.tracking_device_id)
device = ApnsDevice(push_id, device_name, current_tracking_id)
if (current_devic... |
'Send push message to registered devices.'
| def send_message(self, message=None, **kwargs):
| from apns2.client import APNsClient
from apns2.payload import Payload
from apns2.errors import Unregistered
apns = APNsClient(self.certificate, use_sandbox=self.sandbox, use_alternative_port=False)
device_state = kwargs.get(ATTR_TARGET)
message_data = kwargs.get(ATTR_DATA)
if (message_data i... |
'Initialize the service.'
| def __init__(self, default_channel, api_token, username, icon, is_allowed_path):
| from slacker import Slacker
self._default_channel = default_channel
self._api_token = api_token
self._username = username
self._icon = icon
if (self._username or self._icon):
self._as_user = False
else:
self._as_user = True
self.is_allowed_path = is_allowed_path
self.... |
'Send a message to a user.'
| def send_message(self, message='', **kwargs):
| import slacker
if (kwargs.get(ATTR_TARGET) is None):
targets = [self._default_channel]
else:
targets = kwargs.get(ATTR_TARGET)
data = kwargs.get(ATTR_DATA)
attachments = (data.get(ATTR_ATTACHMENTS) if data else None)
file = (data.get(ATTR_FILE) if data else None)
title = kwar... |
'Load image/document/etc from a local path or url.'
| def load_file(self, url=None, local_path=None, username=None, password=None, auth=None):
| try:
if (url is not None):
if ((username is not None) and (password is not None)):
if (ATTR_FILE_AUTH_DIGEST == auth):
auth_ = HTTPDigestAuth(username, password)
else:
auth_ = HTTPBasicAuth(username, password)
... |
'Initialize the service.'
| def __init__(self, sender, client):
| self.sender = sender
self.client = client
|
'Send a message to a specified target.'
| def send_message(self, message=None, **kwargs):
| from messagebird.client import ErrorException
targets = kwargs.get(ATTR_TARGET)
if (not targets):
_LOGGER.error('No target specified')
return
for target in targets:
try:
self.client.message_create(self.sender, target, message, {'reference': 'HA'})
except... |
'Initialize the service.'
| def __init__(self, private_key):
| self._private_key = private_key
|
'Send a message to a user.'
| def send_message(self, message='', **kwargs):
| title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
payload = {'k': self._private_key, 't': title, 'm': message}
response = requests.get(_RESOURCE, params=payload, timeout=DEFAULT_TIMEOUT)
if (response.status_code != 200):
_LOGGER.error('Not possible to send notification')
|
'Initialize the service.'
| def __init__(self, api_key, channel_name, send_test_msg):
| from pushetta import Pushetta
self._api_key = api_key
self._channel_name = channel_name
self.is_valid = True
self.pushetta = Pushetta(api_key)
if send_test_msg:
self.send_message('Home Assistant started')
|
'Send a message to a user.'
| def send_message(self, message='', **kwargs):
| from pushetta import exceptions
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
try:
self.pushetta.pushMessage(self._channel_name, '{} {}'.format(title, message))
except exceptions.TokenValidationError:
_LOGGER.error('Please check your access token')
self.is_val... |
'Initialize the service.'
| def __init__(self, hass, consumer_key, consumer_secret, access_token_key, access_token_secret, username):
| from TwitterAPI import TwitterAPI
self.user = username
self.hass = hass
self.api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret)
|
'Tweet a message, optionally with media.'
| def send_message(self, message='', **kwargs):
| data = kwargs.get(ATTR_DATA)
media = None
if data:
media = data.get(ATTR_MEDIA)
if (not self.hass.config.is_allowed_path(media)):
_LOGGER.warning("'%s' is not a whitelisted directory", media)
return
media_id = self.upload_media(media)
if self.us... |
'Upload media.'
| def upload_media(self, media_path=None):
| if (not media_path):
return None
(media_type, _) = mimetypes.guess_type(media_path)
total_bytes = os.path.getsize(media_path)
file = open(media_path, 'rb')
resp = self.upload_media_init(media_type, total_bytes)
if (199 > resp.status_code < 300):
self.log_error_resp(resp)
... |
'Upload media, INIT phase.'
| def upload_media_init(self, media_type, total_bytes):
| resp = self.api.request('media/upload', {'command': 'INIT', 'media_type': media_type, 'total_bytes': total_bytes})
return resp
|
'Upload media, chunked append.'
| def upload_media_chunked(self, file, total_bytes, media_id):
| segment_id = 0
bytes_sent = 0
while (bytes_sent < total_bytes):
chunk = file.read(((4 * 1024) * 1024))
resp = self.upload_media_append(chunk, media_id, segment_id)
if (resp.status_code not in range(200, 299)):
self.log_error_resp_append(resp)
return None
... |
'Upload media, append phase.'
| def upload_media_append(self, chunk, media_id, segment_id):
| return self.api.request('media/upload', {'command': 'APPEND', 'media_id': media_id, 'segment_index': segment_id}, {'media': chunk})
|
'Upload media, finalize phase.'
| def upload_media_finalize(self, media_id):
| return self.api.request('media/upload', {'command': 'FINALIZE', 'media_id': media_id})
|
'Log upload progress.'
| @staticmethod
def log_bytes_sent(bytes_sent, total_bytes):
| _LOGGER.debug('%s of %s bytes uploaded', str(bytes_sent), str(total_bytes))
|
'Log error response.'
| @staticmethod
def log_error_resp(resp):
| obj = json.loads(resp.text)
error_message = obj['errors']
_LOGGER.error('Error %s: %s', resp.status_code, error_message)
|
'Log error response, during upload append phase.'
| @staticmethod
def log_error_resp_append(resp):
| obj = json.loads(resp.text)
error_message = obj['errors'][0]['message']
error_code = obj['errors'][0]['code']
_LOGGER.error('Error %s: %s (Code %s)', resp.status_code, error_message, error_code)
|
'Initialize the service.'
| def __init__(self, user_key, api_token):
| from pushover import Client
self._user_key = user_key
self._api_token = api_token
self.pushover = Client(self._user_key, api_token=self._api_token)
|
'Send a message to a user.'
| def send_message(self, message='', **kwargs):
| from pushover import RequestError
data = dict((kwargs.get(ATTR_DATA) or {}))
data['title'] = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
targets = kwargs.get(ATTR_TARGET)
if (not isinstance(targets, list)):
targets = [targets]
for target in targets:
if (target is not None):
... |
'Initialize the service.'
| def __init__(self, facility, option, priority):
| self._facility = facility
self._option = option
self._priority = priority
|
'Send a message to a user.'
| def send_message(self, message='', **kwargs):
| import syslog
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
syslog.openlog(title, self._option, self._facility)
syslog.syslog(self._priority, message)
syslog.closelog()
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.