desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Update device state.'
| def update(self):
| super().update()
value = self.get_percentage('getposition')
if (value is not None):
self._current_pos = value
if self._invert_position:
self._current_pos = (100 - value)
_LOGGER.debug('%s: position = %d', self.name, value)
if (self._supported_features & SUPPO... |
'Open the cover.'
| def open_cover(self, **kwargs):
| _LOGGER.debug('%s: open: updown = 0', self.name)
self.set_int_value('updown', 0)
|
'Close the cover.'
| def close_cover(self, **kwargs):
| _LOGGER.debug('%s: open: updown = 1', self.name)
self.set_int_value('updown', 1)
|
'Stop the cover movement.'
| def stop_cover(self, **kwargs):
| _LOGGER.debug('%s: stop: stop = 1', self.name)
self.set_int_value('stop', 1)
|
'Move the cover til to a specific position.'
| def set_cover_tilt_position(self, tilt_position, **kwargs):
| if self._invert_angle:
tilt_position = (100 - tilt_position)
self._target_tilt = round(tilt_position, (-1))
self.set_percentage('setangle', tilt_position)
|
'Return the class of this device, from component DEVICE_CLASSES.'
| @property
def device_class(self):
| return self._device_class
|
'Callback when entity is added to hass.'
| @asyncio.coroutine
def async_added_to_hass(self):
| self.hass.data[DOMAIN]['entities']['cover'].append(self)
|
'Close the shade.'
| def close_cover(self, **kwargs):
| self.wink.set_state(0)
|
'Open the shade.'
| def open_cover(self, **kwargs):
| self.wink.set_state(1)
|
'Move the roller shutter to a specific position.'
| def set_cover_position(self, position, **kwargs):
| self.wink.set_state((float(position) / 100))
|
'Return the current position of roller shutter.'
| @property
def current_cover_position(self):
| return int((self.wink.state() * 100))
|
'Return if the cover is closed.'
| @property
def is_closed(self):
| state = self.wink.state()
return bool((state == 0))
|
'Initialize the Vera device.'
| def __init__(self, vera_device, controller):
| VeraDevice.__init__(self, vera_device, controller)
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
'Return current position of cover.
0 is closed, 100 is fully open.'
| @property
def current_cover_position(self):
| position = self.vera_device.get_level()
if (position <= 5):
return 0
if (position >= 95):
return 100
return position
|
'Move the cover to a specific position.'
| def set_cover_position(self, position, **kwargs):
| self.vera_device.set_level(position)
self.schedule_update_ha_state()
|
'Return if the cover is closed.'
| @property
def is_closed(self):
| if (self.current_cover_position is not None):
return (self.current_cover_position == 0)
|
'Open the cover.'
| def open_cover(self, **kwargs):
| self.vera_device.open()
self.schedule_update_ha_state()
|
'Close the cover.'
| def close_cover(self, **kwargs):
| self.vera_device.close()
self.schedule_update_ha_state()
|
'Stop the cover.'
| def stop_cover(self, **kwargs):
| self.vera_device.stop()
self.schedule_update_ha_state()
|
'Initialize the XiaomiPlug.'
| def __init__(self, device, name, data_key, xiaomi_hub):
| self._data_key = data_key
self._pos = 0
XiaomiDevice.__init__(self, device, name, xiaomi_hub)
|
'Return the current position of the cover.'
| @property
def current_cover_position(self):
| return self._pos
|
'Return if the cover is closed.'
| @property
def is_closed(self):
| return (self.current_cover_position < 0)
|
'Close the cover.'
| def close_cover(self, **kwargs):
| self._write_to_hub(self._sid, self._data_key['status'], 'close')
|
'Open the cover.'
| def open_cover(self, **kwargs):
| self._write_to_hub(self._sid, self._data_key['status'], 'open')
|
'Stop the cover.'
| def stop_cover(self, **kwargs):
| self._write_to_hub(self._sid, self._data_key['status'], 'stop')
|
'Move the cover to a specific position.'
| def set_cover_position(self, position, **kwargs):
| self._write_to_hub(self._sid, self._data_key['pos'], str(position))
|
'Parse data sent by gateway.'
| def parse_data(self, data):
| if (ATTR_CURTAIN_LEVEL in data):
self._pos = int(data[ATTR_CURTAIN_LEVEL])
return True
return False
|
'Initialize the cover.'
| def __init__(self, hass, name, position=None, tilt_position=None, device_class=None, supported_features=None):
| self.hass = hass
self._name = name
self._position = position
self._device_class = device_class
self._supported_features = supported_features
self._set_position = None
self._set_tilt_position = None
self._tilt_position = tilt_position
self._requested_closing = True
self._requested... |
'Return the name of the cover.'
| @property
def name(self):
| return self._name
|
'No polling needed for a demo cover.'
| @property
def should_poll(self):
| return False
|
'Return the current position of the cover.'
| @property
def current_cover_position(self):
| return self._position
|
'Return the current tilt position of the cover.'
| @property
def current_cover_tilt_position(self):
| return self._tilt_position
|
'Return if the cover is closed.'
| @property
def is_closed(self):
| return self._closed
|
'Return if the cover is closing.'
| @property
def is_closing(self):
| return self._is_closing
|
'Return if the cover is opening.'
| @property
def is_opening(self):
| return self._is_opening
|
'Return the class of this device, from component DEVICE_CLASSES.'
| @property
def device_class(self):
| return self._device_class
|
'Flag supported features.'
| @property
def supported_features(self):
| if (self._supported_features is not None):
return self._supported_features
return super().supported_features
|
'Close the cover.'
| def close_cover(self, **kwargs):
| if (self._position == 0):
return
elif (self._position is None):
self._closed = True
self.schedule_update_ha_state()
return
self._is_closing = True
self._listen_cover()
self._requested_closing = True
self.schedule_update_ha_state()
|
'Close the cover tilt.'
| def close_cover_tilt(self, **kwargs):
| if (self._tilt_position in (0, None)):
return
self._listen_cover_tilt()
self._requested_closing_tilt = True
|
'Open the cover.'
| def open_cover(self, **kwargs):
| if (self._position == 100):
return
elif (self._position is None):
self._closed = False
self.schedule_update_ha_state()
return
self._is_opening = True
self._listen_cover()
self._requested_closing = False
self.schedule_update_ha_state()
|
'Open the cover tilt.'
| def open_cover_tilt(self, **kwargs):
| if (self._tilt_position in (100, None)):
return
self._listen_cover_tilt()
self._requested_closing_tilt = False
|
'Move the cover to a specific position.'
| def set_cover_position(self, position, **kwargs):
| self._set_position = round(position, (-1))
if (self._position == position):
return
self._listen_cover()
self._requested_closing = (position < self._position)
|
'Move the cover til to a specific position.'
| def set_cover_tilt_position(self, tilt_position, **kwargs):
| self._set_tilt_position = round(tilt_position, (-1))
if (self._tilt_position == tilt_position):
return
self._listen_cover_tilt()
self._requested_closing_tilt = (tilt_position < self._tilt_position)
|
'Stop the cover.'
| def stop_cover(self, **kwargs):
| self._is_closing = False
self._is_opening = False
if (self._position is None):
return
if (self._unsub_listener_cover is not None):
self._unsub_listener_cover()
self._unsub_listener_cover = None
self._set_position = None
|
'Stop the cover tilt.'
| def stop_cover_tilt(self, **kwargs):
| if (self._tilt_position is None):
return
if (self._unsub_listener_cover_tilt is not None):
self._unsub_listener_cover_tilt()
self._unsub_listener_cover_tilt = None
self._set_tilt_position = None
|
'Listen for changes in cover.'
| def _listen_cover(self):
| if (self._unsub_listener_cover is None):
self._unsub_listener_cover = track_utc_time_change(self.hass, self._time_changed_cover)
|
'Track time changes.'
| def _time_changed_cover(self, now):
| if self._requested_closing:
self._position -= 10
else:
self._position += 10
if (self._position in (100, 0, self._set_position)):
self.stop_cover()
self._closed = (self.current_cover_position <= 0)
self.schedule_update_ha_state()
|
'Listen for changes in cover tilt.'
| def _listen_cover_tilt(self):
| if (self._unsub_listener_cover_tilt is None):
self._unsub_listener_cover_tilt = track_utc_time_change(self.hass, self._time_changed_cover_tilt)
|
'Track time changes.'
| def _time_changed_cover_tilt(self, now):
| if self._requested_closing_tilt:
self._tilt_position -= 10
else:
self._tilt_position += 10
if (self._tilt_position in (100, 0, self._set_tilt_position)):
self.stop_cover_tilt()
self.schedule_update_ha_state()
|
'Initialize the cover.'
| def __init__(self, hass, args):
| self.particle_url = 'https://api.particle.io'
self.hass = hass
self._name = args['name']
self.device_id = args['device_id']
self.access_token = args['access_token']
self.obtained_token = False
self._username = args['username']
self._password = args['password']
self._state = STATE_UNK... |
'Try to remove token.'
| def __del__(self):
| if (self._obtained_token is True):
if (self.access_token is not None):
self.remove_token()
|
'Return the name of the cover.'
| @property
def name(self):
| return self._name
|
'No polling needed for a demo cover.'
| @property
def should_poll(self):
| return True
|
'Return True if entity is available.'
| @property
def available(self):
| return self._available
|
'Return the device state attributes.'
| @property
def device_state_attributes(self):
| data = {}
if (self.signal is not None):
data[ATTR_SIGNAL_STRENGTH] = self.signal
if (self.time_in_state is not None):
data[ATTR_TIME_IN_STATE] = self.time_in_state
if (self.sensor is not None):
data[ATTR_SENSOR_STRENGTH] = self.sensor
if (self.access_token is not None):
... |
'Return if the cover is closed.'
| @property
def is_closed(self):
| if (self._state == STATE_UNKNOWN):
return None
return (self._state == STATE_CLOSED)
|
'Return the class of this device, from component DEVICE_CLASSES.'
| @property
def device_class(self):
| return 'garage'
|
'Get new token for usage during this session.'
| def get_token(self):
| args = {'grant_type': 'password', 'username': self._username, 'password': self._password}
url = '{}/oauth/token'.format(self.particle_url)
ret = requests.post(url, auth=('particle', 'particle'), data=args, timeout=10)
try:
return ret.json()['access_token']
except KeyError:
_LOGGER.er... |
'Remove authorization token from API.'
| def remove_token(self):
| url = '{}/v1/access_tokens/{}'.format(self.particle_url, self.access_token)
ret = requests.delete(url, auth=(self._username, self._password), timeout=10)
return ret.text
|
'Start watcher.'
| def _start_watcher(self, command):
| _LOGGER.debug('Starting Watcher for command: %s ', command)
if (self._unsub_listener_cover is None):
self._unsub_listener_cover = track_utc_time_change(self.hass, self._check_state)
|
'Check the state of the service during an operation.'
| def _check_state(self, now):
| self.schedule_update_ha_state(True)
|
'Close the cover.'
| def close_cover(self):
| if (self._state not in ['close', 'closing']):
ret = self._put_command('setState', 'close')
self._start_watcher('close')
return (ret.get('return_value') == 1)
|
'Open the cover.'
| def open_cover(self):
| if (self._state not in ['open', 'opening']):
ret = self._put_command('setState', 'open')
self._start_watcher('open')
return (ret.get('return_value') == 1)
|
'Stop the door where it is.'
| def stop_cover(self):
| if (self._state not in ['stopped']):
ret = self._put_command('setState', 'stop')
self._start_watcher('stop')
return (ret['return_value'] == 1)
|
'Get updated status from API.'
| def update(self):
| try:
status = self._get_variable('doorStatus')
_LOGGER.debug('Current Status: %s', status['status'])
self._state = STATES_MAP.get(status['status'], STATE_UNKNOWN)
self.time_in_state = status['time']
self.signal = status['signal']
self.sensor = status['sensor']
... |
'Get latest status.'
| def _get_variable(self, var):
| url = '{}/v1/devices/{}/{}?access_token={}'.format(self.particle_url, self.device_id, var, self.access_token)
ret = requests.get(url, timeout=10)
result = {}
for pairs in ret.json()['result'].split('|'):
key = pairs.split('=')
result[key[0]] = key[1]
return result
|
'Send commands to API.'
| def _put_command(self, func, arg=None):
| params = {'access_token': self.access_token}
if arg:
params['command'] = arg
url = '{}/v1/devices/{}/{}'.format(self.particle_url, self.device_id, func)
ret = requests.post(url, data=params, timeout=10)
return ret.json()
|
'Create an event database object from a native event.'
| @staticmethod
def from_event(event):
| return Events(event_type=event.event_type, event_data=json.dumps(event.data, cls=JSONEncoder), origin=str(event.origin), time_fired=event.time_fired)
|
'Convert to a natve HA Event.'
| def to_native(self):
| try:
return Event(self.event_type, json.loads(self.event_data), EventOrigin(self.origin), _process_timestamp(self.time_fired))
except ValueError:
_LOGGER.exception('Error converting to event: %s', self)
return None
|
'Create object from a state_changed event.'
| @staticmethod
def from_event(event):
| entity_id = event.data['entity_id']
state = event.data.get('new_state')
dbstate = States(entity_id=entity_id)
if (state is None):
dbstate.state = ''
dbstate.domain = split_entity_id(entity_id)[0]
dbstate.attributes = '{}'
dbstate.last_changed = event.time_fired
db... |
'Convert to an HA state object.'
| def to_native(self):
| try:
return State(self.entity_id, self.state, json.loads(self.attributes), _process_timestamp(self.last_changed), _process_timestamp(self.last_updated))
except ValueError:
_LOGGER.exception('Error converting row to state: %s', self)
return None
|
'Return the entity ids that existed in this run.
Specify point_in_time if you want to know which existed at that point
in time inside the run.'
| def entity_ids(self, point_in_time=None):
| from sqlalchemy.orm.session import Session
session = Session.object_session(self)
assert (session is not None), 'RecorderRuns need to be persisted'
query = session.query(distinct(States.entity_id)).filter((States.last_updated >= self.start))
if (point_in_time is not None):
query ... |
'Return self, native format is this model.'
| def to_native(self):
| return self
|
'Initialize the FeedManager object, poll every hour.'
| def __init__(self, url, hass, storage):
| self._url = url
self._feed = None
self._hass = hass
self._firstrun = True
self._storage = storage
self._last_entry_timestamp = None
self._has_published_parsed = False
hass.bus.listen_once(EVENT_HOMEASSISTANT_START, (lambda _: self._update()))
track_utc_time_change(hass, (lambda now: ... |
'Send no entries log at debug level.'
| def _log_no_entries(self):
| _LOGGER.debug('No new entries to be published in feed %s', self._url)
|
'Update the feed and publish new entries to the event bus.'
| def _update(self):
| import feedparser
_LOGGER.info('Fetching new data from feed %s', self._url)
self._feed = feedparser.parse(self._url, etag=(None if (not self._feed) else self._feed.get('etag')), modified=(None if (not self._feed) else self._feed.get('modified')))
if (not self._feed):
_LOGGER.error... |
'Update last_entry_timestamp and fire entry.'
| def _update_and_fire_entry(self, entry):
| if ('published_parsed' in entry.keys()):
self._has_published_parsed = True
self._last_entry_timestamp = max(entry.published_parsed, self._last_entry_timestamp)
else:
self._has_published_parsed = False
_LOGGER.debug('No published_parsed info available for entry %... |
'Publish new entries to the event bus.'
| def _publish_new_entries(self):
| new_entries = False
self._last_entry_timestamp = self._storage.get_timestamp(self._url)
if self._last_entry_timestamp:
self._firstrun = False
else:
self._last_entry_timestamp = datetime.utcfromtimestamp(0).timetuple()
for entry in self._feed.entries:
if (self._firstrun or (('... |
'Initialize pickle data storage.'
| def __init__(self, data_file):
| self._data_file = data_file
self._lock = Lock()
self._cache_outdated = True
self._data = {}
self._fetch_data()
|
'Fetch data stored into pickle file.'
| def _fetch_data(self):
| if (self._cache_outdated and exists(self._data_file)):
try:
_LOGGER.debug('Fetching data from file %s', self._data_file)
with self._lock:
with open(self._data_file, 'rb') as myfile:
self._data = (pickle.load(myfile) or {})
... |
'Return stored timestamp for given url.'
| def get_timestamp(self, url):
| self._fetch_data()
return self._data.get(url)
|
'Update timestamp for given URL.'
| def put_timestamp(self, url, timestamp):
| self._fetch_data()
with self._lock:
with open(self._data_file, 'wb') as myfile:
self._data.update({url: timestamp})
_LOGGER.debug('Overwriting feed %s timestamp in storage file %s', url, self._data_file)
try:
pickle.dump(self._data... |
'Initialize the sun.'
| def __init__(self, hass, location):
| self.hass = hass
self.location = location
self._state = self.next_rising = self.next_setting = None
self.next_dawn = self.next_dusk = None
self.next_midnight = self.next_noon = None
self.solar_elevation = self.solar_azimuth = None
async_track_utc_time_change(hass, self.timer_update, second=3... |
'Return the name.'
| @property
def name(self):
| return 'Sun'
|
'Return the state of the sun.'
| @property
def state(self):
| if (self.next_rising > self.next_setting):
return STATE_ABOVE_HORIZON
return STATE_BELOW_HORIZON
|
'Return the state attributes of the sun.'
| @property
def state_attributes(self):
| return {STATE_ATTR_NEXT_DAWN: self.next_dawn.isoformat(), STATE_ATTR_NEXT_DUSK: self.next_dusk.isoformat(), STATE_ATTR_NEXT_MIDNIGHT: self.next_midnight.isoformat(), STATE_ATTR_NEXT_NOON: self.next_noon.isoformat(), STATE_ATTR_NEXT_RISING: self.next_rising.isoformat(), STATE_ATTR_NEXT_SETTING: self.next_setting.iso... |
'Datetime when the next change to the state is.'
| @property
def next_change(self):
| return min(self.next_dawn, self.next_dusk, self.next_midnight, self.next_noon, self.next_rising, self.next_setting)
|
'Update the attributes containing solar events.'
| @callback
def update_as_of(self, utc_point_in_time):
| self.next_dawn = get_astral_event_next(self.hass, 'dawn', utc_point_in_time)
self.next_dusk = get_astral_event_next(self.hass, 'dusk', utc_point_in_time)
self.next_midnight = get_astral_event_next(self.hass, 'solar_midnight', utc_point_in_time)
self.next_noon = get_astral_event_next(self.hass, 'solar_no... |
'Calculate the position of the sun.'
| @callback
def update_sun_position(self, utc_point_in_time):
| self.solar_azimuth = self.location.solar_azimuth(utc_point_in_time)
self.solar_elevation = self.location.solar_elevation(utc_point_in_time)
|
'Run when the state of the sun has changed.'
| @callback
def point_in_time_listener(self, now):
| self.update_sun_position(now)
self.update_as_of(now)
self.hass.async_add_job(self.async_update_ha_state())
async_track_point_in_utc_time(self.hass, self.point_in_time_listener, (self.next_change + timedelta(seconds=1)))
|
'Needed to update solar elevation and azimuth.'
| @callback
def timer_update(self, time):
| self.update_sun_position(time)
self.hass.async_add_job(self.async_update_ha_state())
|
'Initialize the data oject.'
| def __init__(self, host, port):
| from apcaccess import status
self._host = host
self._port = port
self._status = None
self._get = status.get
self._parse = status.parse
|
'Get latest update if throttle allows. Return status.'
| @property
def status(self):
| self.update()
return self._status
|
'Get the status from APCUPSd and parse it into a dict.'
| def _get_status(self):
| return self._parse(self._get(host=self._host, port=self._port))
|
'Fetch the latest status from APCUPSd.'
| @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self, **kwargs):
| self._status = self._get_status()
|
'Set up the base class.
[:param]device the device metadata
[:param]bridge the smartbridge object'
| def __init__(self, device, bridge):
| self._device_id = device['device_id']
self._device_type = device['type']
self._device_name = device['name']
self._device_zone = device['zone']
self._state = None
self._smartbridge = bridge
|
'Register callbacks.'
| @asyncio.coroutine
def async_added_to_hass(self):
| self.hass.async_add_job(self._smartbridge.add_subscriber, self._device_id, self._update_callback)
|
'Return the name of the device.'
| @property
def name(self):
| return self._device_name
|
'Return the state attributes.'
| @property
def device_state_attributes(self):
| attr = {'Device ID': self._device_id, 'Zone ID': self._device_zone}
return attr
|
'No polling needed.'
| @property
def should_poll(self):
| return False
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.