desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Initialize our printer.'
def __init__(self, _getattr_):
pass
'Print text.'
def _call_print(self, *objects, **kwargs):
_LOGGER.warning("Don't use print() inside scripts. Use logger.info() instead.")
'Initialize a PyMochad controller.'
def __init__(self, host, port):
super(MochadCtrl, self).__init__() self._host = host self._port = port from pymochad import controller self.ctrl = controller.PyMochad(server=self._host, port=self._port)
'Return the server where mochad is running.'
@property def host(self):
return self._host
'Return the port mochad is running on.'
@property def port(self):
return self._port
'Close the connection to the mochad socket.'
def disconnect(self):
self.ctrl.socket.close()
'Initialize the device.'
def __init__(self, name, event, datas, signal_repetitions):
self.signal_repetitions = signal_repetitions self._name = name self._event = event self._state = datas[ATTR_STATE] self._should_fire_event = datas[ATTR_FIREEVENT] self._brightness = 0
'No polling needed for a RFXtrx switch.'
@property def should_poll(self):
return False
'Return the name of the device if any.'
@property def name(self):
return self._name
'Return is the device must fire event.'
@property def should_fire_event(self):
return self._should_fire_event
'Return true if device is on.'
@property def is_on(self):
return self._state
'Return true if unable to access real state of entity.'
@property def assumed_state(self):
return True
'Turn the device off.'
def turn_off(self, **kwargs):
self._send_command('turn_off')
'Update det state of the device.'
def update_state(self, state, brightness=0):
self._state = state self._brightness = brightness self.schedule_update_ha_state()
'Init the Ecobee data object.'
def __init__(self, config_file):
from pyecobee import Ecobee self.ecobee = Ecobee(config_file)
'Get the latest data from pyecobee.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
self.ecobee.update() _LOGGER.info('Ecobee data updated successfully')
'Initialize the Tellus data object.'
def __init__(self, hass, config):
from tellduslive import Client public_key = config[DOMAIN].get(CONF_PUBLIC_KEY) private_key = config[DOMAIN].get(CONF_PRIVATE_KEY) token = config[DOMAIN].get(CONF_TOKEN) token_secret = config[DOMAIN].get(CONF_TOKEN_SECRET) self.entities = [] self._hass = hass self._config = config se...
'Make a request to see if the session is valid.'
def validate_session(self):
response = self._client.request_user() return (response and ('email' in response))
'Periodically poll the servers for current state.'
def update(self, *args):
_LOGGER.debug('Updating') try: self._sync() finally: track_point_in_utc_time(self._hass, self.update, (utcnow() + self._interval))
'Update local list of devices.'
def _sync(self):
if (not self._client.update()): _LOGGER.warning('Failed request') def identify_device(device): 'Find out what type of HA component to create.' from tellduslive import DIM, UP, TURNON if (device.methods & DIM): return 'light' elif (de...
'Return device representation.'
def device(self, device_id):
return self._client.device(device_id)
'Return device availability.'
def is_available(self, device_id):
return (device_id in self._client.device_ids)
'Initialize the entity.'
def __init__(self, hass, device_id):
self._id = device_id self._client = hass.data[DOMAIN] self._client.entities.append(self) self._name = self.device.name _LOGGER.debug('Created device %s', self)
'Return the property of the device might have changed.'
def changed(self):
if self.device.name: self._name = self.device.name self.schedule_update_ha_state()
'Return the id of the device.'
@property def device_id(self):
return self._id
'Return the representaion of the device.'
@property def device(self):
return self._client.device(self.device_id)
'Return the state of the device.'
@property def _state(self):
return self.device.state
'Return the polling state.'
@property def should_poll(self):
return False
'Return true if unable to access real state of entity.'
@property def assumed_state(self):
return True
'Return name of device.'
@property def name(self):
return (self._name or DEVICE_DEFAULT_NAME)
'Return true if device is not offline.'
@property def available(self):
return self._client.is_available(self.device_id)
'Return the state attributes.'
@property def device_state_attributes(self):
attrs = {} if self._battery_level: attrs[ATTR_BATTERY_LEVEL] = self._battery_level if self._last_updated: attrs[ATTR_LAST_UPDATED] = self._last_updated return attrs
'Return the battery level of a device.'
@property def _battery_level(self):
return (round(((self.device.battery * 100) / 255)) if self.device.battery else None)
'Return the last update of a device.'
@property def _last_updated(self):
return (str(datetime.fromtimestamp(self.device.lastUpdated)) if self.device.lastUpdated else None)
'Initialize HomeMatic hub.'
def __init__(self, hass, name, use_variables):
self.hass = hass self.entity_id = '{}.{}'.format(DOMAIN, name.lower()) self._homematic = hass.data[DATA_HOMEMATIC] self._variables = {} self._name = name self._state = STATE_UNKNOWN self._use_variables = use_variables track_time_interval(hass, self._update_hub, SCAN_INTERVAL_HUB) sel...
'Return the name of the device.'
@property def name(self):
return self._name
'Return false. HomeMatic Hub object updates variables.'
@property def should_poll(self):
return False
'Return the state of the entity.'
@property def state(self):
return self._state
'Return the state attributes.'
@property def state_attributes(self):
attr = self._variables.copy() return attr
'Return the icon to use in the frontend, if any.'
@property def icon(self):
return 'mdi:gradient'
'Retrieve latest state.'
def _update_hub(self, now):
state = self._homematic.getServiceMessages(self._name) self._state = (STATE_UNKNOWN if (state is None) else len(state)) self.schedule_update_ha_state()
'Retrive all variable data and update hmvariable states.'
def _update_variables(self, now):
variables = self._homematic.getAllSystemVariables(self._name) if (variables is None): return state_change = False for (key, value) in variables.items(): if ((key in self._variables) and (value == self._variables[key])): continue state_change = True self._varia...
'Set variable value on CCU/Homegear.'
def hm_set_variable(self, name, value):
if (name not in self._variables): _LOGGER.error('Variable %s not found on %s', name, self.name) return old_value = self._variables.get(name) if isinstance(old_value, bool): value = cv.boolean(value) else: value = float(value) self._homematic.setSystemVa...
'Initialize a generic HomeMatic device.'
def __init__(self, hass, config):
self.hass = hass self._homematic = hass.data[DATA_HOMEMATIC] self._name = config.get(ATTR_NAME) self._address = config.get(ATTR_ADDRESS) self._proxy = config.get(ATTR_PROXY) self._channel = config.get(ATTR_CHANNEL) self._state = config.get(ATTR_PARAM) self._data = {} self._hmdevice =...
'Return false. HomeMatic states are pushed by the XML-RPC Server.'
@property def should_poll(self):
return False
'Return the name of the device.'
@property def name(self):
return self._name
'Return true if unable to access real state of the device.'
@property def assumed_state(self):
return (not self._available)
'Return true if device is available.'
@property def available(self):
return self._available
'Return device specific state attributes.'
@property def device_state_attributes(self):
attr = {} if (not self.available): return attr for (node, data) in HM_ATTRIBUTE_SUPPORT.items(): if (node in self._data): value = data[1].get(self._data[node], self._data[node]) attr[data[0]] = value attr['id'] = self._hmdevice.ADDRESS attr['proxy'] = self._pr...
'Connect to HomeMatic.'
def link_homematic(self):
if self._connected: return True self._hmdevice = self._homematic.devices[self._proxy][self._address] self._connected = True try: self._init_data() if self.hass.data[DATA_DELAY]: time.sleep(self.hass.data[DATA_DELAY]) self._load_data_from_hm() self._sub...
'Handle all pyhomematic device events.'
def _hm_event_callback(self, device, caller, attribute, value):
_LOGGER.debug("%s received event '%s' value: %s", self._name, attribute, value) has_changed = False if (attribute in self._data): if (self._data[attribute] != value): self._data[attribute] = value has_changed = True if (attribute == 'UNREACH'): self...
'Subscribe all required events to handle job.'
def _subscribe_homematic_events(self):
channels_to_sub = set() channels_to_sub.add(0) for metadata in (self._hmdevice.SENSORNODE, self._hmdevice.BINARYNODE, self._hmdevice.ATTRIBUTENODE, self._hmdevice.WRITENODE, self._hmdevice.EVENTNODE, self._hmdevice.ACTIONNODE): for (node, channels) in metadata.items(): if (node in self._...
'Load first value from pyhomematic.'
def _load_data_from_hm(self):
if (not self._connected): return False for (metadata, funct) in ((self._hmdevice.ATTRIBUTENODE, self._hmdevice.getAttributeData), (self._hmdevice.WRITENODE, self._hmdevice.getWriteData), (self._hmdevice.SENSORNODE, self._hmdevice.getSensorData), (self._hmdevice.BINARYNODE, self._hmdevice.getBinaryData))...
'Set data to main datapoint.'
def _hm_set_state(self, value):
if (self._state in self._data): self._data[self._state] = value
'Get data from main datapoint.'
def _hm_get_state(self):
if (self._state in self._data): return self._data[self._state] return None
'Generate a data dict (self._data) from the HomeMatic metadata.'
def _init_data(self):
for data_note in self._hmdevice.ATTRIBUTENODE: self._data.update({data_note: STATE_UNKNOWN}) self._init_data_struct()
'Generate a data dictionary from the HomeMatic device metadata.'
def _init_data_struct(self):
raise NotImplementedError
'Initialize the configuration.'
def __init__(self, config):
self._config = config self._should_poll = config.get('poll', True)
'Return the name given to the entity.'
@property def name(self):
return self._config['name']
'Return the address of the device. If an address has been provided, unhexlify it, otherwise return None as we\'re talking to our local ZigBee device.'
@property def address(self):
address = self._config.get('address') if (address is not None): address = unhexlify(address) return address
'Return the polling state.'
@property def should_poll(self):
return self._should_poll
'Return the GPIO pin number.'
@property def pin(self):
return self._config['pin']
'Initialise the ZigBee Digital input config.'
def __init__(self, config):
super(ZigBeeDigitalInConfig, self).__init__(config) (self._bool2state, self._state2bool) = self.boolean_maps
'Create mapping dictionaries for potential inversion of booleans. Create dicts to map the pin state (true/false) to potentially inverted values depending on the on_state config value which should be set to "low" or "high".'
@property def boolean_maps(self):
if (self._config.get('on_state', '').lower() == 'low'): bool2state = {True: False, False: True} else: bool2state = {True: True, False: False} state2bool = {v: k for (k, v) in bool2state.items()} return (bool2state, state2bool)
'Return a dictionary mapping the internal value to the ZigBee value. For the translation of on/off as being pin high or low.'
@property def bool2state(self):
return self._bool2state
'Return a dictionary mapping the ZigBee value to the internal value. For the translation of pin high/low as being on or off.'
@property def state2bool(self):
return self._state2bool
'Initialize the ZigBee Digital out.'
def __init__(self, config):
super(ZigBeeDigitalOutConfig, self).__init__(config) (self._bool2state, self._state2bool) = self.boolean_maps self._should_poll = config.get('poll', False)
'Create dicts to map booleans to pin high/low and vice versa. Depends on the config item "on_state" which should be set to "low" or "high".'
@property def boolean_maps(self):
if (self._config.get('on_state', '').lower() == 'low'): bool2state = {True: GPIO_DIGITAL_OUTPUT_LOW, False: GPIO_DIGITAL_OUTPUT_HIGH} else: bool2state = {True: GPIO_DIGITAL_OUTPUT_HIGH, False: GPIO_DIGITAL_OUTPUT_LOW} state2bool = {v: k for (k, v) in bool2state.items()} return (bool2stat...
'Return a dictionary mapping booleans to GPIOSetting objects. For the translation of on/off as being pin high or low.'
@property def bool2state(self):
return self._bool2state
'Return a dictionary mapping GPIOSetting objects to booleans. For the translation of pin high/low as being on or off.'
@property def state2bool(self):
return self._state2bool
'Return the voltage for ADC to report its highest value.'
@property def max_voltage(self):
return float(self._config.get('max_volts', DEFAULT_ADC_MAX_VOLTS))
'Initialize the device.'
def __init__(self, hass, config):
self._config = config self._state = False
'Register callbacks.'
@asyncio.coroutine def async_added_to_hass(self):
def handle_frame(frame): 'Handle an incoming frame.\n\n Handle an incoming frame and update our status if it contains\n information relating to this device.\n ...
'Return the name of the input.'
@property def name(self):
return self._config.name
'Return the entity\'s configuration.'
@property def config(self):
return self._config
'Return the state of the polling, if needed.'
@property def should_poll(self):
return self._config.should_poll
'Return True if the Entity is on, else False.'
@property def is_on(self):
return self._state
'Ask the ZigBee device what state its input pin is in.'
def update(self):
try: sample = DEVICE.get_sample(self._config.address) except ZIGBEE_TX_FAILURE: _LOGGER.warning('Transmission failure when attempting to get sample from ZigBee device at address: %s', hexlify(self._config.address)) return except ZIGBEE_EXCEPTION as...
'Initialize the ZigBee digital out device.'
def _set_state(self, state):
try: DEVICE.set_gpio_pin(self._config.pin, self._config.bool2state[state], self._config.address) except ZIGBEE_TX_FAILURE: _LOGGER.warning('Transmission failure when attempting to set output pin on ZigBee device at address: %s', hexlify(self._config.address...
'Set the digital output to its \'on\' state.'
def turn_on(self, **kwargs):
self._set_state(True)
'Set the digital output to its \'off\' state.'
def turn_off(self, **kwargs):
self._set_state(False)
'Ask the ZigBee device what its output is set to.'
def update(self):
try: pin_state = DEVICE.get_gpio_pin(self._config.pin, self._config.address) except ZIGBEE_TX_FAILURE: _LOGGER.warning('Transmission failure when attempting to get output pin status from ZigBee device at address: %s', hexlify(self._config.address)) ...
'Initialize the ZigBee analog in device.'
def __init__(self, hass, config):
self._config = config self._value = None
'Register callbacks.'
@asyncio.coroutine def async_added_to_hass(self):
def handle_frame(frame): 'Handle an incoming frame.\n\n Handle an incoming frame and update our status if it contains\n information relating to this device.\n ...
'Return the name of the input.'
@property def name(self):
return self._config.name
'Return the entity\'s configuration.'
@property def config(self):
return self._config
'Return the polling state, if needed.'
@property def should_poll(self):
return self._config.should_poll
'Return the state of the entity.'
@property def state(self):
return self._value
'Return the unit this state is expressed in.'
@property def unit_of_measurement(self):
return '%'
'Get the latest reading from the ADC.'
def update(self):
try: self._value = DEVICE.read_analog_pin(self._config.pin, self._config.max_voltage, self._config.address, ADC_PERCENTAGE) except ZIGBEE_TX_FAILURE: _LOGGER.warning('Transmission failure when attempting to get sample from ZigBee device at address: %s', hexlif...
'Initialize an X10 Light.'
def __init__(self, light):
self._name = light['name'] self._id = light['id'] self._brightness = 0 self._state = False
'Return the display name of this light.'
@property def name(self):
return self._name
'Return the brightness of the light.'
@property def brightness(self):
return self._brightness
'Return true if light is on.'
@property def is_on(self):
return self._state
'Flag supported features.'
@property def supported_features(self):
return SUPPORT_X10
'Instruct the light to turn on.'
def turn_on(self, **kwargs):
x10_command(('on ' + self._id)) self._brightness = kwargs.get(ATTR_BRIGHTNESS, 255) self._state = True
'Instruct the light to turn off.'
def turn_off(self, **kwargs):
x10_command(('off ' + self._id)) self._state = False
'Fetch update state.'
def update(self):
self._state = bool(get_unit_status(self._id))
'Initialize the light.'
def __init__(self, stick, name):
self._stick = stick self._name = name self._serial = stick.get_serial() self._rgb_color = stick.get_color()
'Set up polling.'
@property def should_poll(self):
return True