desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Get the name of the pin.'
@property def name(self):
return self._name
'Return true if pin is high/on.'
@property def is_on(self):
return self._state
'Turn the pin to high/on.'
def turn_on(self):
self._state = True self.turn_on_handler(self._pin)
'Turn the pin to low/off.'
def turn_off(self):
self._state = False self.turn_off_handler(self._pin)
'Initialize the Transmission switch.'
def __init__(self, transmission_client, name):
self._name = name self.transmission_client = transmission_client self._state = STATE_OFF
'Return the name of the switch.'
@property def name(self):
return self._name
'Return the state of the device.'
@property def state(self):
return self._state
'Poll for status regularly.'
@property def should_poll(self):
return True
'Return true if device is on.'
@property def is_on(self):
return (self._state == STATE_ON)
'Turn the device on.'
def turn_on(self, **kwargs):
_LOGGING.debug('Turning Turtle Mode of Transmission on') self.transmission_client.set_session(alt_speed_enabled=True)
'Turn the device off.'
def turn_off(self, **kwargs):
_LOGGING.debug('Turning Turtle Mode of Transmission off') self.transmission_client.set_session(alt_speed_enabled=False)
'Get the latest data from Transmission and updates the state.'
def update(self):
active = self.transmission_client.get_session().alt_speed_enabled self._state = (STATE_ON if active else STATE_OFF)
'Initialize the pin.'
def __init__(self, pin, params):
self._pin = pin self._name = (params.get(CONF_NAME) or DEVICE_DEFAULT_NAME) self._state = params.get(CONF_INITIAL) self._invert_logic = params.get(CONF_INVERT_LOGIC) bbb_gpio.setup_output(self._pin) if (self._state is False): bbb_gpio.write_output(self._pin, (1 if self._invert_logic else...
'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):
bbb_gpio.write_output(self._pin, (0 if self._invert_logic else 1)) self._state = True self.schedule_update_ha_state()
'Turn the device off.'
def turn_off(self, **kwargs):
bbb_gpio.write_output(self._pin, (1 if self._invert_logic else 0)) self._state = False self.schedule_update_ha_state()
'Initialize a new device.'
def __init__(self, rachio, device_id, manual_run_mins):
self.rachio = rachio self._device_id = device_id self.manual_run_mins = manual_run_mins self._device = None self._running = None self._zones = None
'Display the device as a string.'
def __str__(self):
return ('Rachio Iro ' + self.serial_number)
'How the Rachio API refers to the device.'
@property def device_id(self):
return self._device['id']
'The current status of the device.'
@property def status(self):
return self._device['status']
'The serial number of the device.'
@property def serial_number(self):
return self._device['serialNumber']
'Whether the device is temporarily disabled.'
@property def is_paused(self):
return self._device['paused']
'Whether the device is powered on and connected.'
@property def is_on(self):
return self._device['on']
'The schedule that the device is running right now.'
@property def current_schedule(self):
return self._running
'A list of the zones connected to the device and their data.'
def list_zones(self, include_disabled=False):
if (not self._zones): self._zones = [RachioZone(self.rachio, self, zone['id'], self.manual_run_mins) for zone in self._device['zones']] if include_disabled: return self._zones self.update(no_throttle=True) return [z for z in self._zones if z.is_enabled]
'Pull updated device info from the Rachio API.'
@util.Throttle(MIN_UPDATE_INTERVAL, MIN_FORCED_UPDATE_INTERVAL) def update(self, **kwargs):
self._device = self.rachio.device.get(self._device_id)[1] self._running = self.rachio.device.getCurrentSchedule(self._device_id)[1] for zone in self.list_zones(include_disabled=True): zone.update() _LOGGER.debug('Updated %s', str(self))
'Initialize a new Rachio Zone.'
def __init__(self, rachio, device, zone_id, manual_run_mins):
self.rachio = rachio self._device = device self._zone_id = zone_id self._zone = None self._manual_run_secs = (manual_run_mins * 60)
'Display the zone as a string.'
def __str__(self):
return ('Rachio Zone ' + self.name)
'How the Rachio API refers to the zone.'
@property def zone_id(self):
return self._zone['id']
'Generate a unique string ID for the zone.'
@property def unique_id(self):
return '{iro}-{zone}'.format(iro=self._device.device_id, zone=self.zone_id)
'The physical connection of the zone pump.'
@property def number(self):
return self._zone['zoneNumber']
'The friendly name of the zone.'
@property def name(self):
return self._zone['name']
'Whether the zone is allowed to run.'
@property def is_enabled(self):
return self._zone['enabled']
'Whether the zone is currently running.'
@property def is_on(self):
self._device.update() schedule = self._device.current_schedule return (self.zone_id == schedule.get('zoneId'))
'Pull updated zone info from the Rachio API.'
def update(self):
self._zone = self.rachio.zone.get(self._zone_id)[1] self._device.update() _LOGGER.debug('Updated %s', str(self))
'Start the zone.'
def turn_on(self):
self.turn_off() _LOGGER.info('Watering %s for %d s', self.name, self._manual_run_secs) self.rachio.zone.start(self.zone_id, self._manual_run_secs)
'Stop all zones.'
def turn_off(self):
_LOGGER.info('Stopping watering of all zones') self.rachio.device.stopWater(self._device.device_id)
'Initialize the Flux switch.'
def __init__(self, name, hass, state, lights, start_time, stop_time, start_colortemp, sunset_colortemp, stop_colortemp, brightness, disable_brightness_adjust, mode):
self._name = name self.hass = hass self._lights = lights self._start_time = start_time self._stop_time = stop_time self._start_colortemp = start_colortemp self._sunset_colortemp = sunset_colortemp self._stop_colortemp = stop_colortemp self._brightness = brightness self._disable_b...
'Return the name of the device if any.'
@property def name(self):
return self._name
'Return true if switch is on.'
@property def is_on(self):
return (self.unsub_tracker is not None)
'Turn on flux.'
def turn_on(self, **kwargs):
if self.is_on: return self.flux_update() self.unsub_tracker = track_time_change(self.hass, self.flux_update, second=[0, 30]) self.schedule_update_ha_state()
'Turn off flux.'
def turn_off(self, **kwargs):
if (self.unsub_tracker is not None): self.unsub_tracker() self.unsub_tracker = None self.schedule_update_ha_state()
'Update all the lights using flux.'
def flux_update(self, now=None):
if (now is None): now = dt_now() sunset = get_astral_event_date(self.hass, 'sunset', now.date()) start_time = self.find_start_time(now) stop_time = now.replace(hour=self._stop_time.hour, minute=self._stop_time.minute, second=0) if (start_time < now < sunset): time_state = 'day' ...
'Return sunrise or start_time if given.'
def find_start_time(self, now):
if self._start_time: sunrise = now.replace(hour=self._start_time.hour, minute=self._start_time.minute, second=0) else: sunrise = get_astral_event_date(self.hass, 'sunrise', now.date()) return sunrise
'Initialize the Vera device.'
def __init__(self, vera_device, controller):
self._state = False VeraDevice.__init__(self, vera_device, controller) self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
'Turn device on.'
def turn_on(self, **kwargs):
self.vera_device.switch_on() self._state = True self.schedule_update_ha_state()
'Turn device off.'
def turn_off(self, **kwargs):
self.vera_device.switch_off() self._state = False self.schedule_update_ha_state()
'Return the current power usage in W.'
@property def current_power_w(self):
power = self.vera_device.power if power: return convert(power, float, 0.0)
'Return true if device is on.'
@property def is_on(self):
return self._state
'Update device state.'
def update(self):
self._state = self.vera_device.is_switched_on()
'Initialize the switch.'
def __init__(self, smartplug, name):
self.smartplug = smartplug if (name is None): self._name = self.smartplug.alias else: self._name = name self._state = None _LOGGER.debug('Setting up TP-Link Smart Plug') self._emeter_params = {}
'Return the name of the Smart Plug, if any.'
@property def name(self):
return self._name
'Return true if switch is on.'
@property def is_on(self):
return self._state
'Turn the switch on.'
def turn_on(self, **kwargs):
self.smartplug.turn_on()
'Turn the switch off.'
def turn_off(self):
self.smartplug.turn_off()
'Return the state attributes of the device.'
@property def device_state_attributes(self):
return self._emeter_params
'Update the TP-Link switch\'s state.'
def update(self):
from pyHS100 import SmartPlugException try: self._state = (self.smartplug.state == self.smartplug.SWITCH_STATE_ON) if self.smartplug.has_emeter: emeter_readings = self.smartplug.get_emeter_realtime() self._emeter_params[ATTR_CURRENT_CONSUMPTION] = ('%.1f W' % emeter_re...
'Initialize the WOL switch.'
def __init__(self, hass, name, host, mac_address, off_action, broadcast_address):
from wakeonlan import wol self._hass = hass self._name = name self._host = host self._mac_address = mac_address self._broadcast_address = broadcast_address self._off_script = (Script(hass, off_action) if off_action else None) self._state = False self._wol = wol
'Return the polling state.'
@property def should_poll(self):
return True
'Return true if switch is on.'
@property def is_on(self):
return self._state
'Return the name of the switch.'
@property def name(self):
return self._name
'Turn the device on.'
def turn_on(self):
if self._broadcast_address: self._wol.send_magic_packet(self._mac_address, ip_address=self._broadcast_address) else: self._wol.send_magic_packet(self._mac_address)
'Turn the device off if an off action is present.'
def turn_off(self):
if (self._off_script is not None): self._off_script.run()
'Check if device is on and update the state.'
def update(self):
if (platform.system().lower() == 'windows'): ping_cmd = ['ping', '-n', '1', '-w', str((DEFAULT_PING_TIMEOUT * 1000)), str(self._host)] else: ping_cmd = ['ping', '-c', '1', '-W', str(DEFAULT_PING_TIMEOUT), str(self._host)] status = sp.call(ping_cmd, stdout=sp.DEVNULL, stderr=sp.DEVNULL) s...
'Initialize the XiaomiPlug.'
def __init__(self, device, name, data_key, supports_power_consumption, xiaomi_hub):
self._data_key = data_key self._in_use = None self._load_power = None self._power_consumed = None self._supports_power_consumption = supports_power_consumption XiaomiDevice.__init__(self, device, name, xiaomi_hub)
'Return the icon to use in the frontend, if any.'
@property def icon(self):
if (self._data_key == 'status'): return 'mdi:power-plug' return 'mdi:power-socket'
'Return true if it is on.'
@property def is_on(self):
return self._state
'Return the state attributes.'
@property def device_state_attributes(self):
if self._supports_power_consumption: attrs = {ATTR_IN_USE: self._in_use, ATTR_LOAD_POWER: self._load_power, ATTR_POWER_CONSUMED: self._power_consumed} else: attrs = {} attrs.update(super().device_state_attributes) return attrs
'Turn the switch on.'
def turn_on(self, **kwargs):
if self._write_to_hub(self._sid, **{self._data_key: 'on'}): self._state = True self.schedule_update_ha_state()
'Turn the switch off.'
def turn_off(self):
if self._write_to_hub(self._sid, **{self._data_key: 'off'}): self._state = False self.schedule_update_ha_state()
'Parse data sent by gateway.'
def parse_data(self, data):
if (IN_USE in data): self._in_use = int(data[IN_USE]) if (not self._in_use): self._load_power = 0 if (POWER_CONSUMED in data): self._power_consumed = round(float(data[POWER_CONSUMED]), 2) if (LOAD_POWER in data): self._load_power = round(float(data[LOAD_POWER]), 2...
'Initialize the mFi device.'
def __init__(self, port):
self._port = port self._target_state = None
'Return the polling state.'
@property def should_poll(self):
return True
'Return the unique ID of the device.'
@property def unique_id(self):
return self._port.ident
'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.output
'Get the latest state and update the state.'
def update(self):
self._port.refresh() if (self._target_state is not None): self._port.data['output'] = float(self._target_state) self._target_state = None
'Turn the switch on.'
def turn_on(self, **kwargs):
self._port.control(True) self._target_state = True
'Turn the switch off.'
def turn_off(self, **kwargs):
self._port.control(False) self._target_state = False
'Return the current power usage in W.'
@property def current_power_w(self):
return int(self._port.data.get('active_pwr', 0))
'Return the state attributes fof the device.'
@property def device_state_attributes(self):
attr = {} attr['volts'] = round(self._port.data.get('v_rms', 0), 1) attr['amps'] = round(self._port.data.get('i_rms', 0), 1) return attr
'Initialize the Demo switch.'
def __init__(self, name, state, icon, assumed):
self._name = (name or DEVICE_DEFAULT_NAME) self._state = state self._icon = icon self._assumed = assumed
'No polling needed for a demo switch.'
@property def should_poll(self):
return False
'Return the name of the device if any.'
@property def name(self):
return self._name
'Return the icon to use for device if any.'
@property def icon(self):
return self._icon
'Return if the state is based on assumptions.'
@property def assumed_state(self):
return self._assumed
'Return the current power usage in W.'
@property def current_power_w(self):
if self._state: return 100
'Return the today total energy usage in kWh.'
@property def today_energy_kwh(self):
return 15
'Return true if switch is on.'
@property def is_on(self):
return self._state
'Turn the switch on.'
def turn_on(self, **kwargs):
self._state = True self.schedule_update_ha_state()
'Turn the device off.'
def turn_off(self, **kwargs):
self._state = False self.schedule_update_ha_state()
'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 Smart Plug, if any.'
@property def name(self):
return self._name
'Return the state attributes of the device.'
@property def device_state_attributes(self):
try: ui_temp = self.units.temperature(int(self.data.temperature), TEMP_CELSIUS) temperature = ('%i %s' % (ui_temp, self.units.temperature_unit)) except (ValueError, TypeError): temperature = STATE_UNKNOWN try: current_consumption = ('%.2f W' % float(self.data.current_co...
'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 == 'ON')
'Turn the switch on.'
def turn_on(self, **kwargs):
self.data.smartplug.state = 'ON'
'Turn the switch off.'
def turn_off(self):
self.data.smartplug.state = 'OFF'