desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Initialize the switch.'
def __init__(self, resource, location, name, func):
super().__init__(resource, location, name) self._func = func request = requests.get('{}/{}'.format(self._resource, self._func), timeout=10) if (request.status_code != 200): _LOGGER.error("Can't find function") return try: request.json()['return_value'] except KeyErr...
'Turn the device on.'
def turn_on(self, **kwargs):
request = requests.get('{}/{}'.format(self._resource, self._func), timeout=10, params={'params': '1'}) if (request.status_code == 200): self._state = True else: _LOGGER.error("Can't turn on function %s at %s", self._func, self._resource)
'Turn the device off.'
def turn_off(self, **kwargs):
request = requests.get('{}/{}'.format(self._resource, self._func), timeout=10, params={'params': '0'}) if (request.status_code == 200): self._state = False else: _LOGGER.error("Can't turn off function %s at %s", self._func, self._resource)
'Get the latest data from aREST API and update the state.'
def update(self):
try: request = requests.get('{}/{}'.format(self._resource, self._func), timeout=10) self._state = (request.json()['return_value'] != 0) self._available = True except requests.exceptions.ConnectionError: _LOGGER.warning('No route to device %s', self._resource) ...
'Initialize the switch.'
def __init__(self, resource, location, name, pin):
super().__init__(resource, location, name) self._pin = pin request = requests.get('{}/mode/{}/o'.format(self._resource, self._pin), timeout=10) if (request.status_code != 200): _LOGGER.error("Can't set mode") self._available = False
'Turn the device on.'
def turn_on(self, **kwargs):
request = requests.get('{}/digital/{}/1'.format(self._resource, self._pin), timeout=10) if (request.status_code == 200): self._state = True else: _LOGGER.error("Can't turn on pin %s at %s", self._pin, self._resource)
'Turn the device off.'
def turn_off(self, **kwargs):
request = requests.get('{}/digital/{}/0'.format(self._resource, self._pin), timeout=10) if (request.status_code == 200): self._state = False else: _LOGGER.error("Can't turn off pin %s at %s", self._pin, self._resource)
'Get the latest data from aREST API and update the state.'
def update(self):
try: request = requests.get('{}/digital/{}'.format(self._resource, self._pin), timeout=10) self._state = (request.json()['return_value'] != 0) self._available = True except requests.exceptions.ConnectionError: _LOGGER.warning('No route to device %s', self._resource) ...
'Turn the switch on.'
def turn_on(self, **kwargs):
self._smartbridge.turn_on(self._device_id)
'Turn the switch off.'
def turn_off(self, **kwargs):
self._smartbridge.turn_off(self._device_id)
'Return true if device is on.'
@property def is_on(self):
return (self._state['current_state'] > 0)
'Update when forcing a refresh of the device.'
def update(self):
self._state = self._smartbridge.get_device_by_id(self._device_id) _LOGGER.debug(self._state)
'Initialize a Mochad Switch Device.'
def __init__(self, hass, ctrl, dev):
from pymochad import device self._controller = ctrl self._address = dev[CONF_ADDRESS] self._name = dev.get(CONF_NAME, ('x10_switch_dev_%s' % self._address)) self._comm_type = dev.get(mochad.CONF_COMM_TYPE, 'pl') self.device = device.Device(ctrl, self._address, comm_type=self._comm_type) self...
'Get the name of the switch.'
@property def name(self):
return self._name
'Turn the switch on.'
def turn_on(self, **kwargs):
self._state = True self.device.send_cmd('on') self._controller.read_data()
'Turn the switch off.'
def turn_off(self, **kwargs):
self._state = False self.device.send_cmd('off') self._controller.read_data()
'Get the status of the switch from mochad.'
def _get_device_status(self):
status = self.device.get_status().rstrip() return (status == 'on')
'Return true if switch is on.'
@property def is_on(self):
return self._state
'Turn the device on.'
def turn_on(self, **kwargs):
self._send_command('turn_on')
'Initialize the switch.'
def __init__(self, monitor_id, monitor_name, on_state, off_state):
self._monitor_id = monitor_id self._monitor_name = monitor_name self._on_state = on_state self._off_state = off_state self._state = None
'Return the name of the switch.'
@property def name(self):
return ('%s State' % self._monitor_name)
'Update the switch value.'
def update(self):
monitor = zoneminder.get_state(('api/monitors/%i.json' % self._monitor_id)) current_state = monitor['monitor']['Monitor']['Function'] self._state = (True if (current_state == self._on_state) else False)
'Return True if entity is on.'
@property def is_on(self):
return self._state
'Turn the entity on.'
def turn_on(self):
zoneminder.change_state(('api/monitors/%i.json' % self._monitor_id), {'Monitor[Function]': self._on_state})
'Turn the entity off.'
def turn_off(self):
zoneminder.change_state(('api/monitors/%i.json' % self._monitor_id), {'Monitor[Function]': self._off_state})
'Return true if switch is on.'
@property def is_on(self):
return self.device.is_on
'Turn the switch on.'
def turn_on(self, **kwargs):
self.device.turn_on() self.changed()
'Turn the switch off.'
def turn_off(self, **kwargs):
self.device.turn_off() self.changed()
'Return True if switch is on.'
@property def is_on(self):
try: return (self._hm_get_state() > 0) except TypeError: return False
'Return the current power usage in kWh.'
@property def today_energy_kwh(self):
if ('ENERGY_COUNTER' in self._data): try: return (self._data['ENERGY_COUNTER'] / 1000) except ZeroDivisionError: return 0 return None
'Turn the switch on.'
def turn_on(self, **kwargs):
self._hmdevice.on(self._channel)
'Turn the switch off.'
def turn_off(self, **kwargs):
self._hmdevice.off(self._channel)
'Generate the data dictionary (self._data) from metadata.'
def _init_data_struct(self):
self._state = 'STATE' self._data.update({self._state: STATE_UNKNOWN}) for node in self._hmdevice.SENSORNODE: self._data.update({node: STATE_UNKNOWN})
'Initialize the device.'
def __init__(self, hass, name, host, port, path, user, passwd):
self._hass = hass self._name = name self._state = False self._url = 'http://{}:{}{}'.format(host, port, path) if (user is not None): self._auth = (user, passwd) else: self._auth = None
'Switch on or off.'
def _switch(self, newstate):
_LOGGER.info('Switching to state: %s', newstate) try: req = requests.get('{}?set={}'.format(self._url, newstate), auth=self._auth, timeout=5) return req.json()['ok'] except requests.RequestException: _LOGGER.error('Switching failed')
'Query switch state.'
def _query_state(self):
_LOGGER.info('Querying state from: %s', self._url) try: req = requests.get('{}?get=state'.format(self._url), auth=self._auth, timeout=5) return (req.json()['state'] == 'on') except requests.RequestException: _LOGGER.error('State query failed')
'Return the polling state.'
@property def should_poll(self):
return True
'Return the name of the switch.'
@property def name(self):
return self._name
'Return true if device is on.'
@property def is_on(self):
return self._state
'Update device state.'
def update(self):
self._state = self._query_state()
'Turn the device on.'
def turn_on(self, **kwargs):
if self._switch('on'): self._state = True
'Turn the device off.'
def turn_off(self, **kwargs):
if self._switch('off'): self._state = False
'Initialize the PwrCtrl switch.'
def __init__(self, port, parent_device):
self._port = port self._parent_device = parent_device
'Return the polling state.'
@property def should_poll(self):
return True
'Return the unique ID of the device.'
@property def unique_id(self):
return '{device}-{switch_idx}'.format(device=self._port.device.host, switch_idx=self._port.get_index())
'Return the name of the device.'
@property def name(self):
return self._port.label
'Return true if the device is on.'
@property def is_on(self):
return self._port.get_state()
'Trigger update for all switches on the parent device.'
def update(self):
self._parent_device.update()
'Turn the switch on.'
def turn_on(self):
self._port.on()
'Turn the switch off.'
def turn_off(self):
self._port.off()
'Initialize the PwrCtrl device.'
def __init__(self, device):
self._device = device
'Update the device and all its switches.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
self._device.update()
'Initialize the pin.'
def __init__(self, name, port, invert_logic):
self._name = (name or DEVICE_DEFAULT_NAME) self._port = port self._invert_logic = invert_logic self._state = False rpi_gpio.setup_output(self._port) rpi_gpio.write_output(self._port, (1 if self._invert_logic else 0))
'Return the name of the switch.'
@property def name(self):
return self._name
'No polling needed.'
@property def should_poll(self):
return False
'Return true if device is on.'
@property def is_on(self):
return self._state
'Turn the device on.'
def turn_on(self, **kwargs):
rpi_gpio.write_output(self._port, (0 if self._invert_logic else 1)) self._state = True self.schedule_update_ha_state()
'Turn the device off.'
def turn_off(self, **kwargs):
rpi_gpio.write_output(self._port, (1 if self._invert_logic else 0)) self._state = False self.schedule_update_ha_state()
'Initialize the DIN III Relay switch.'
def __init__(self, name, outletnumber, parent_device):
self._parent_device = parent_device self.controllername = name self.outletnumber = outletnumber self._outletname = '' self._is_on = False
'Return the display name of this relay.'
@property def name(self):
return self._outletname
'Return true if relay is on.'
@property def is_on(self):
return self._is_on
'Return the polling state.'
@property def should_poll(self):
return True
'Instruct the relay to turn on.'
def turn_on(self, **kwargs):
self._parent_device.turn_on(outlet=self.outletnumber)
'Instruct the relay to turn off.'
def turn_off(self, **kwargs):
self._parent_device.turn_off(outlet=self.outletnumber)
'Trigger update for all switches on the parent device.'
def update(self):
self._parent_device.update() self._is_on = (self._parent_device.statuslocal[(self.outletnumber - 1)][2] == 'ON') self._outletname = '{}_{}'.format(self.controllername, self._parent_device.statuslocal[(self.outletnumber - 1)][1])
'Initialize the DINRelay device.'
def __init__(self, device):
self._device = device self.statuslocal = None
'Instruct the relay to turn on.'
def turn_on(self, **kwargs):
self._device.on(**kwargs)
'Instruct the relay to turn off.'
def turn_off(self, **kwargs):
self._device.off(**kwargs)
'Fetch new state data for this device.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
self.statuslocal = self._device.statuslist()
'Return True if unable to access real state of entity.'
@property def assumed_state(self):
return self.gateway.optimistic
'Return True if switch is on.'
@property def is_on(self):
if (self.value_type in self._values): return (self._values[self.value_type] == STATE_ON) return False
'Turn the switch on.'
def turn_on(self, **kwargs):
self.gateway.set_child_value(self.node_id, self.child_id, self.value_type, 1) if self.gateway.optimistic: self._values[self.value_type] = STATE_ON self.schedule_update_ha_state()
'Turn the switch off.'
def turn_off(self, **kwargs):
self.gateway.set_child_value(self.node_id, self.child_id, self.value_type, 0) if self.gateway.optimistic: self._values[self.value_type] = STATE_OFF self.schedule_update_ha_state()
'Set up instance attributes.'
def __init__(self, *args):
MySensorsSwitch.__init__(self, *args) self._ir_code = None
'Return True if switch is on.'
@property def is_on(self):
set_req = self.gateway.const.SetReq if (set_req.V_LIGHT in self._values): return (self._values[set_req.V_LIGHT] == STATE_ON) return False
'Turn the IR switch on.'
def turn_on(self, **kwargs):
set_req = self.gateway.const.SetReq if (set_req.V_LIGHT not in self._values): _LOGGER.error('missing value_type: %s at node: %s, child: %s', set_req.V_LIGHT.name, self.node_id, self.child_id) return if (ATTR_IR_CODE in kwargs): self._ir_code = kwargs[ATTR_IR_CODE...
'Turn the IR switch off.'
def turn_off(self, **kwargs):
set_req = self.gateway.const.SetReq if (set_req.V_LIGHT not in self._values): _LOGGER.error('missing value_type: %s at node: %s, child: %s', set_req.V_LIGHT.name, self.node_id, self.child_id) return self.gateway.set_child_value(self.node_id, self.child_id, set_req.V_LIGH...
'Update the controller with the latest value from a sensor.'
def update(self):
MySensorsSwitch.update(self) if (self.value_type in self._values): self._ir_code = self._values[self.value_type]
'Initialize the pin.'
def __init__(self, port, name, invert_logic):
self._port = port self._name = (name or DEVICE_DEFAULT_NAME) self._invert_logic = invert_logic self._state = False rpi_pfio.write_output(self._port, (1 if self._invert_logic else 0))
'Return the name of the switch.'
@property def name(self):
return self._name
'No polling needed.'
@property def should_poll(self):
return False
'Return true if device is on.'
@property def is_on(self):
return self._state
'Turn the device on.'
def turn_on(self):
rpi_pfio.write_output(self._port, (0 if self._invert_logic else 1)) self._state = True self.schedule_update_ha_state()
'Turn the device off.'
def turn_off(self):
rpi_pfio.write_output(self._port, (1 if self._invert_logic else 0)) self._state = False self.schedule_update_ha_state()
'Initialize the Z-Wave switch device.'
def __init__(self, values):
zwave.ZWaveDeviceEntity.__init__(self, values, DOMAIN) self.refresh_on_update = (workaround.get_device_mapping(values.primary) == workaround.WORKAROUND_REFRESH_NODE_ON_UPDATE) self.last_update = time.perf_counter() self._state = self.values.primary.data
'Handle data changes for node values.'
def update_properties(self):
self._state = self.values.primary.data if (self.refresh_on_update and ((time.perf_counter() - self.last_update) > 30)): self.last_update = time.perf_counter() self.node.request_state()
'Return true if device is on.'
@property def is_on(self):
return self._state
'Turn the device on.'
def turn_on(self, **kwargs):
self.node.set_switch(self.values.primary.value_id, True)
'Turn the device off.'
def turn_off(self, **kwargs):
self.node.set_switch(self.values.primary.value_id, False)
'Initialize the switch.'
def __init__(self, hass, data, name):
self.units = hass.config.units self.data = data self._name = name
'Return the name of the FRITZ!DECT switch, if any.'
@property def name(self):
return self._name
'Return the state attributes of the device.'
@property def device_state_attributes(self):
attrs = {} if (self.data.has_powermeter and (self.data.current_consumption != STATE_UNKNOWN) and (self.data.total_consumption != STATE_UNKNOWN)): attrs[ATTR_CURRENT_CONSUMPTION] = '{:.1f}'.format(self.data.current_consumption) attrs[ATTR_CURRENT_CONSUMPTION_UNIT] = '{}'.format(ATTR_CURRENT_CONSU...
'Return the current power usage in Watt.'
@property def current_power_watt(self):
try: return float(self.data.current_consumption) except ValueError: return None
'Return true if switch is on.'
@property def is_on(self):
return self.data.state
'Turn the switch on.'
def turn_on(self, **kwargs):
actor = self.data.fritz.get_actor_by_ain(self.data.ain) actor.switch_on()
'Turn the switch off.'
def turn_off(self):
actor = self.data.fritz.get_actor_by_ain(self.data.ain) actor.switch_off()
'Get the latest data from the fritz box and updates the states.'
def update(self):
self.data.update()
'Initialize the data object.'
def __init__(self, fritz, ain):
self.fritz = fritz self.ain = ain self.state = STATE_UNKNOWN self.temperature = STATE_UNKNOWN self.current_consumption = STATE_UNKNOWN self.total_consumption = STATE_UNKNOWN self.has_switch = STATE_UNKNOWN self.has_temperature = STATE_UNKNOWN self.has_powermeter = STATE_UNKNOWN
'Get the latest data from the fritz box.'
def update(self):
from requests.exceptions import RequestException try: actor = self.fritz.get_actor_by_ain(self.ain) self.state = actor.get_state() except RequestException: _LOGGER.error('Request to actor failed') self.state = STATE_UNKNOWN self.temperature = STATE_UNKNOWN ...
'Initialize the switch.'
def __init__(self, scs_id, name, logger):
self._name = name self._scs_id = scs_id self._toggled = False self._logger = logger