desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Flag supported features.'
| @property
def supported_features(self):
| return SUPPORT_TELLSTICK
|
'Turn the value from HA into something useful.'
| def _parse_ha_data(self, kwargs):
| return kwargs.get(ATTR_BRIGHTNESS)
|
'Turn the value recieved from tellcore into something useful.'
| def _parse_tellcore_data(self, tellcore_data):
| if (tellcore_data is not None):
brightness = int(tellcore_data)
return brightness
return None
|
'Update the device entity state to match the arguments.'
| def _update_model(self, new_state, data):
| if new_state:
brightness = data
if (brightness is not None):
self._brightness = brightness
try:
self._state = (self._brightness > 0)
except AttributeError:
self._state = True
else:
self._state = False
|
'Let tellcore update the actual device to the requested state.'
| def _send_device_command(self, requested_state, requested_data):
| if requested_state:
if (requested_data is not None):
self._brightness = int(requested_data)
self._tellcore_device.dim(self._brightness)
else:
self._tellcore_device.turn_off()
|
'Initialize the light.'
| def __init__(self, vera_device, controller):
| self._state = False
self._color = None
self._brightness = None
VeraDevice.__init__(self, vera_device, controller)
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
'Return the brightness of the light.'
| @property
def brightness(self):
| return self._brightness
|
'Return the color of the light.'
| @property
def rgb_color(self):
| return self._color
|
'Flag supported features.'
| @property
def supported_features(self):
| if self._color:
return (SUPPORT_BRIGHTNESS | SUPPORT_RGB_COLOR)
return SUPPORT_BRIGHTNESS
|
'Turn the light on.'
| def turn_on(self, **kwargs):
| if ((ATTR_RGB_COLOR in kwargs) and self._color):
self.vera_device.set_color(kwargs[ATTR_RGB_COLOR])
elif ((ATTR_BRIGHTNESS in kwargs) and self.vera_device.is_dimmable):
self.vera_device.set_brightness(kwargs[ATTR_BRIGHTNESS])
else:
self.vera_device.switch_on()
self._state = True
... |
'Turn the light off.'
| def turn_off(self, **kwargs):
| self.vera_device.switch_off()
self._state = False
self.schedule_update_ha_state()
|
'Return true if device is on.'
| @property
def is_on(self):
| return self._state
|
'Call to update state.'
| def update(self):
| self._state = self.vera_device.is_switched_on()
if self.vera_device.is_dimmable:
self._brightness = self.vera_device.get_brightness()
self._color = self.vera_device.get_color()
|
'Initialize the bulb.'
| def __init__(self, smartbulb, name):
| self.smartbulb = smartbulb
if (name is None):
self._name = self.smartbulb.alias
else:
self._name = name
self._state = None
self._color_temp = None
self._brightness = None
_LOGGER.debug('Setting up TP-Link Smart Bulb')
|
'Return the name of the Smart Bulb, if any.'
| @property
def name(self):
| return self._name
|
'Turn the light on.'
| def turn_on(self, **kwargs):
| if (ATTR_COLOR_TEMP in kwargs):
self.smartbulb.color_temp = mired_to_kelvin(kwargs[ATTR_COLOR_TEMP])
if (ATTR_KELVIN in kwargs):
self.smartbulb.color_temp = kwargs[ATTR_KELVIN]
if (ATTR_BRIGHTNESS in kwargs):
brightness = kwargs.get(ATTR_BRIGHTNESS, (self.brightness or 255))
... |
'Turn the light off.'
| def turn_off(self):
| self.smartbulb.state = self.smartbulb.BULB_STATE_OFF
|
'Return the color temperature of this light in mireds for HA.'
| @property
def color_temp(self):
| return self._color_temp
|
'Return the brightness of this light between 0..255.'
| @property
def brightness(self):
| return self._brightness
|
'True if device is on.'
| @property
def is_on(self):
| return self._state
|
'Update the TP-Link Bulb\'s state.'
| def update(self):
| from pyHS100 import SmartPlugException
try:
self._state = (self.smartbulb.state == self.smartbulb.BULB_STATE_ON)
self._brightness = brightness_from_percentage(self.smartbulb.brightness)
if self.smartbulb.is_color:
if ((self.smartbulb.color_temp is not None) and (self.smartbul... |
'Flag supported features.'
| @property
def supported_features(self):
| return SUPPORT_TPLINK
|
'Initialize the light.'
| def __init__(self, device):
| import decora
self._name = device['name']
self._address = device['address']
self._key = device['key']
self._switch = decora.decora(self._address, self._key)
self._brightness = 0
self._state = False
|
'Return the ID of this light.'
| @property
def unique_id(self):
| return '{}.{}'.format(self.__class__, self._address)
|
'Return the name of the device if any.'
| @property
def name(self):
| return self._name
|
'Return true if device is on.'
| @property
def is_on(self):
| return self._state
|
'Return the brightness of this light between 0..255.'
| @property
def brightness(self):
| return self._brightness
|
'Flag supported features.'
| @property
def supported_features(self):
| return SUPPORT_DECORA_LED
|
'We can read the device state, so poll.'
| @property
def should_poll(self):
| return True
|
'We can read the actual state.'
| @property
def assumed_state(self):
| return False
|
'Set the state of this lamp to the provided brightness.'
| @retry
def set_state(self, brightness):
| self._switch.set_brightness(int((brightness / 2.55)))
self._brightness = brightness
|
'Turn the specified or all lights on.'
| @retry
def turn_on(self, **kwargs):
| brightness = kwargs.get(ATTR_BRIGHTNESS)
self._switch.on()
self._state = True
if (brightness is not None):
self.set_state(brightness)
|
'Turn the specified or all lights off.'
| @retry
def turn_off(self, **kwargs):
| self._switch.off()
self._state = False
|
'Synchronise internal state with the actual light state.'
| @retry
def update(self):
| self._brightness = (self._switch.get_brightness() * 2.55)
self._state = self._switch.get_on()
|
'Initialize the XiaomiGatewayLight.'
| def __init__(self, device, name, xiaomi_hub):
| self._data_key = 'rgb'
self._rgb = (255, 255, 255)
self._brightness = 180
XiaomiDevice.__init__(self, device, name, xiaomi_hub)
|
'Return true if it is on.'
| @property
def is_on(self):
| return self._state
|
'Parse data sent by gateway.'
| def parse_data(self, data):
| value = data.get(self._data_key)
if (value is None):
return False
if (value == 0):
if self._state:
self._state = False
return True
rgbhexstr = ('%x' % value)
if (len(rgbhexstr) == 7):
rgbhexstr = ('0' + rgbhexstr)
elif (len(rgbhexstr) != 8):
_L... |
'Return the brightness of this light between 0..255.'
| @property
def brightness(self):
| return self._brightness
|
'Return the RBG color value.'
| @property
def rgb_color(self):
| return self._rgb
|
'Return the supported features.'
| @property
def supported_features(self):
| return (SUPPORT_BRIGHTNESS | SUPPORT_RGB_COLOR)
|
'Turn the light on.'
| def turn_on(self, **kwargs):
| if (ATTR_RGB_COLOR in kwargs):
self._rgb = kwargs[ATTR_RGB_COLOR]
if (ATTR_BRIGHTNESS in kwargs):
self._brightness = int(((100 * kwargs[ATTR_BRIGHTNESS]) / 255))
rgba = ((self._brightness,) + self._rgb)
rgbhex = binascii.hexlify(struct.pack('BBBB', *rgba)).decode('ASCII')
rgbhex = in... |
'Turn the light off.'
| def turn_off(self, **kwargs):
| if self._write_to_hub(self._sid, **{self._data_key: 0}):
self._state = False
|
'Init Luminary object.'
| def __init__(self, luminary, update_lights):
| self.update_lights = update_lights
self._luminary = luminary
self._brightness = None
self._rgb = [None]
self._name = None
self._temperature = None
self._state = False
self.update()
|
'Return the name of the device if any.'
| @property
def name(self):
| return self._name
|
'Last RGB color value set.'
| @property
def rgb_color(self):
| return self._rgb
|
'Return the color temperature.'
| @property
def color_temp(self):
| return self._temperature
|
'Brightness of this light between 0..255.'
| @property
def brightness(self):
| return self._brightness
|
'Update Status to True if device is on.'
| @property
def is_on(self):
| return self._state
|
'Flag supported features.'
| @property
def supported_features(self):
| return SUPPORT_OSRAMLIGHTIFY
|
'List of supported effects.'
| @property
def effect_list(self):
| return [EFFECT_RANDOM]
|
'Turn the device on.'
| def turn_on(self, **kwargs):
| if (ATTR_TRANSITION in kwargs):
transition = int((kwargs[ATTR_TRANSITION] * 10))
_LOGGER.debug('turn_on requested transition time for light: %s is: %s', self._name, transition)
else:
transition = 0
_LOGGER.debug('turn_on requested transition time ... |
'Turn the device off.'
| def turn_off(self, **kwargs):
| _LOGGER.debug('turn_off Attempting to turn off light: %s ', self._name)
if (ATTR_TRANSITION in kwargs):
transition = int((kwargs[ATTR_TRANSITION] * 10))
_LOGGER.debug('turn_off requested transition time for light: %s is: %s ', self._name, transitio... |
'Synchronize state with bridge.'
| def update(self):
| self.update_lights(no_throttle=True)
self._name = self._luminary.name()
|
'Initialize the light.'
| def __init__(self, light_id, light, update_lights):
| self._light_id = light_id
super().__init__(light, update_lights)
|
'Update status of a Light.'
| def update(self):
| super().update()
self._state = self._luminary.on()
self._rgb = self._luminary.rgb()
o_temp = self._luminary.temp()
if (o_temp == 0):
self._temperature = None
else:
self._temperature = color_temperature_kelvin_to_mired(self._luminary.temp())
self._brightness = int((self._lumin... |
'Init light group.'
| def __init__(self, group, bridge, update_lights):
| self._bridge = bridge
self._light_ids = []
super().__init__(group, update_lights)
|
'Get state of group.
The group is on, if any of the lights in on.'
| def _get_state(self):
| lights = self._bridge.lights()
return any((lights[light_id].on() for light_id in self._light_ids))
|
'Update group status.'
| def update(self):
| super().update()
self._light_ids = self._luminary.lights()
light = self._bridge.lights()[self._light_ids[0]]
self._brightness = int((light.lum() * 2.55))
self._rgb = light.rgb()
o_temp = light.temp()
if (o_temp == 0):
self._temperature = None
else:
self._temperature = col... |
'Initialise the sensor.'
| def __init__(self, device, sensor_type, hass):
| self.hass = hass
self.device = device
self.type = sensor_type
|
'Return the name of the device.'
| @property
def name(self):
| return self.device.name()
|
'Update state of the device.'
| def update(self):
| self.device.update_state()
|
'Return the manufacturer device id.'
| @property
def _manufacturer_device_id(self):
| return self.device.id()
|
'Return the device API token.'
| @property
def _token(self):
| return self.device.token()
|
'Return an unique ID.'
| @property
def unique_id(self):
| return '{}-{}'.format(self.device.id(), self.type)
|
'Initialize the configurator.'
| def __init__(self, hass):
| self.hass = hass
self._cur_id = 0
self._requests = {}
hass.services.async_register(DOMAIN, SERVICE_CONFIGURE, self.handle_service_call)
|
'Set up a request for configuration.'
| def request_config(self, name, callback, description, description_image, submit_caption, fields, link_name, link_url, entity_picture):
| entity_id = generate_entity_id(ENTITY_ID_FORMAT, name, hass=self.hass)
if (fields is None):
fields = []
request_id = self._generate_unique_id()
self._requests[request_id] = (entity_id, fields, callback)
data = {ATTR_CONFIGURE_ID: request_id, ATTR_FIELDS: fields, ATTR_FRIENDLY_NAME: name, ATT... |
'Update the state with errors.'
| def notify_errors(self, request_id, error):
| if (not self._validate_request_id(request_id)):
return
entity_id = self._requests[request_id][0]
state = self.hass.states.get(entity_id)
new_data = dict(state.attributes)
new_data[ATTR_ERRORS] = error
self.hass.states.set(entity_id, STATE_CONFIGURE, new_data)
|
'Remove the configuration request.'
| def request_done(self, request_id):
| if (not self._validate_request_id(request_id)):
return
entity_id = self._requests.pop(request_id)[0]
self.hass.states.set(entity_id, STATE_CONFIGURED)
def deferred_remove(event):
'Remove the request state.'
self.hass.states.remove(entity_id)
self.hass.bus.listen_once... |
'Handle a configure service call.'
| def handle_service_call(self, call):
| request_id = call.data.get(ATTR_CONFIGURE_ID)
if (not self._validate_request_id(request_id)):
return
(entity_id, fields, callback) = self._requests[request_id]
self.hass.async_add_job(callback, call.data.get(ATTR_FIELDS, {}))
|
'Generate a unique configurator ID.'
| def _generate_unique_id(self):
| self._cur_id += 1
return '{}-{}'.format(id(self), self._cur_id)
|
'Validate that the request belongs to this instance.'
| def _validate_request_id(self, request_id):
| return (request_id in self._requests)
|
'Set up the class attributes on instantiation.
Args:
gateway (mysensors.SerialGateway): Gateway to wrap.
optimistic (bool): Send values to actuators without feedback state.
device (str): Path to serial port, ip adress or mqtt.
Attributes:
_wrapped_gateway (mysensors.SerialGateway): Wrapped gateway.
platform_callbacks (... | def __init__(self, gateway, optimistic, device):
| self._wrapped_gateway = gateway
self.platform_callbacks = []
self.optimistic = optimistic
self.device = device
self.__initialised = True
|
'See if this object has attribute name.'
| def __getattr__(self, name):
| if (name in self.__dict__):
return getattr(self, name)
return getattr(self._wrapped_gateway, name)
|
'See if this object has attribute name then set to value.'
| def __setattr__(self, name, value):
| if ('_GatewayWrapper__initialised' not in self.__dict__):
return object.__setattr__(self, name, value)
elif (name in self.__dict__):
object.__setattr__(self, name, value)
else:
object.__setattr__(self._wrapped_gateway, name, value)
|
'Return a new callback function.'
| def callback_factory(self):
| def node_update(msg):
'Handle node updates from the MySensors gateway.'
_LOGGER.debug('Update: node %s, child %s sub_type %s', msg.node_id, msg.child_id, msg.sub_type)
for callback in self.platform_callbacks:
callback(self, msg)
return node... |
'Set up the MySensors device.'
| def __init__(self, gateway, node_id, child_id, name, value_type):
| self.gateway = gateway
self.node_id = node_id
self.child_id = child_id
self._name = name
self.value_type = value_type
child = gateway.sensors[node_id].children[child_id]
self.child_type = child.type
self._values = {}
|
'Mysensor gateway pushes its state to HA.'
| @property
def should_poll(self):
| return False
|
'Return the name of this entity.'
| @property
def name(self):
| return self._name
|
'Return device specific state attributes.'
| @property
def device_state_attributes(self):
| node = self.gateway.sensors[self.node_id]
child = node.children[self.child_id]
attr = {ATTR_BATTERY_LEVEL: node.battery_level, ATTR_CHILD_ID: self.child_id, ATTR_DESCRIPTION: child.description, ATTR_DEVICE: self.gateway.device, ATTR_NODE_ID: self.node_id}
set_req = self.gateway.const.SetReq
for (val... |
'Return true if entity is available.'
| @property
def available(self):
| return (self.value_type in self._values)
|
'Update the controller with the latest value from a sensor.'
| def update(self):
| node = self.gateway.sensors[self.node_id]
child = node.children[self.child_id]
set_req = self.gateway.const.SetReq
for (value_type, value) in child.values.items():
_LOGGER.debug('%s: value_type %s, value = %s', self._name, value_type, value)
if (value_type in (set_req.V_AR... |
'Initialize the data object.'
| def __init__(self, client):
| self._client = client
self.beds = {}
self.update()
|
'Get the latest data from SleepIQ.'
| @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
| self._client.login()
beds = self._client.beds_with_sleeper_status()
self.beds = {bed.bed_id: bed for bed in beds}
|
'Initialize the sensor.'
| def __init__(self, sleepiq_data, bed_id, side):
| self._bed_id = bed_id
self._side = side
self.sleepiq_data = sleepiq_data
self.side = None
self.bed = None
self._name = None
self.type = None
|
'Return the name of the sensor.'
| @property
def name(self):
| return 'SleepNumber {} {} {}'.format(self.bed.name, self.side.sleeper.first_name, self._name)
|
'Get the latest data from SleepIQ and updates the states.'
| def update(self):
| self.sleepiq_data.update()
self.bed = self.sleepiq_data.beds[self._bed_id]
self.side = getattr(self.bed, self._side)
|
'Init the Asterisk data object.'
| def __init__(self, hass, host, port, password):
| from asterisk_mbox import Client as asteriskClient
self.hass = hass
self.client = asteriskClient(host, port, password, self.handle_data)
self.messages = []
async_dispatcher_connect(self.hass, SIGNAL_MESSAGE_REQUEST, self._request_messages)
|
'Handle changes to the mailbox.'
| @callback
def handle_data(self, command, msg):
| from asterisk_mbox.commands import CMD_MESSAGE_LIST
if (command == CMD_MESSAGE_LIST):
_LOGGER.info('AsteriskVM sent updated message list')
self.messages = sorted(msg, key=(lambda item: item['info']['origtime']), reverse=True)
async_dispatcher_send(self.hass, SIGNAL_MESSAGE_UP... |
'Handle changes to the mailbox.'
| @callback
def _request_messages(self):
| _LOGGER.info('Requesting message list')
self.client.messages()
|
'Initialize the SCSGate.'
| def __init__(self, device, logger):
| self._logger = logger
self._devices = {}
self._devices_to_register = {}
self._devices_to_register_lock = Lock()
self._device_being_registered = None
self._device_being_registered_lock = Lock()
from scsgate.connection import Connection
connection = Connection(device=device, logger=self._l... |
'Handle a messages seen on the bus.'
| def handle_message(self, message):
| from scsgate.messages import StateMessage, ScenarioTriggeredMessage
self._logger.debug('Received message {}'.format(message))
if ((not isinstance(message, StateMessage)) and (not isinstance(message, ScenarioTriggeredMessage))):
msg = 'Ignored message {} - not releavant type'.... |
'Return a dictionary with known devices.
Key is device ID, value is the device itself.'
| @property
def devices(self):
| return self._devices
|
'Add the specified device.
The list contain already registered ones.
Beware: this is not what you usually want to do, take a look at
`add_devices_to_register`'
| def add_device(self, device):
| self._devices[device.scs_id] = device
|
'List of devices to be registered.'
| def add_devices_to_register(self, devices):
| with self._devices_to_register_lock:
for device in devices:
self._devices_to_register[device.scs_id] = device
self._activate_next_device()
|
'Start the activation of the first device.'
| def _activate_next_device(self):
| from scsgate.tasks import GetStatusTask
with self._devices_to_register_lock:
while self._devices_to_register:
(_, device) = self._devices_to_register.popitem()
self._devices[device.scs_id] = device
self._device_being_registered = device.scs_id
self._reacto... |
'Check whether a device is already registered or not.'
| def is_device_registered(self, device_id):
| with self._devices_to_register_lock:
if (device_id in self._devices_to_register.keys()):
return False
with self._device_being_registered_lock:
if (device_id == self._device_being_registered):
return False
return True
|
'Start the scsgate.Reactor.'
| def start(self):
| self._reactor.start()
|
'Stop the scsgate.Reactor.'
| def stop(self):
| self._reactor.stop()
|
'Register a new task to be executed.'
| def append_task(self, task):
| self._reactor.append_task(task)
|
'Initialize the modbus hub.'
| def __init__(self, modbus_client):
| self._client = modbus_client
self._lock = threading.Lock()
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.