Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Representation of a WeMo Dimmer device."""
from .switch import Switch
class Dimmer(Switch):
"""Representation of a WeMo Dimmer device."""
def __init__(self, *args, **kwargs):
"""Create a WeMo Dimmer device."""
Switch.__init__(self, *args, **kwargs)
self._brightness = None
def get_brightness(self, force_update=False):
"""Get brightness from device."""
if force_update or self._brightness is None:
try:
# pylint: disable=maybe-no-member
brightness = self.basicevent.GetBinaryState().get('brightness')
except ValueError:
brightness = 0
self._brightness = brightness
"""Representation of a WeMo Maker device."""
from xml.etree import cElementTree as et
from .switch import Switch
class Maker(Switch):
"""Representation of a WeMo Maker device."""
def __repr__(self):
"""Return a string representation of the device."""
return ''.format(name=self.name)
@property
def maker_params(self):
"""Get and parse the device attributes."""
# pylint: disable=maybe-no-member
makerresp = self.deviceevent.GetAttributes().get('attributeList')
makerresp = "" + makerresp + ""
makerresp = makerresp.replace(">", ">")
makerresp = makerresp.replace("<", "<")
attributes = et.fromstring(makerresp)
for attribute in attributes:
def device_from_uuid_and_location(uuid, location):
""" Tries to determine which device it is based on the uuid. """
if uuid.startswith('uuid:Socket'):
return Switch(location)
elif uuid.startswith('uuid:Lightswitch'):
return LightSwitch(location)
elif uuid.startswith('uuid:Insight'):
return Insight(location)
elif uuid.startswith('uuid:Sensor'):
return Motion(location)
else:
return None
def device_from_uuid_and_location(uuid, mac, location,
rediscovery_enabled=True):
"""Determine device class based on the device uuid."""
if uuid is None:
return None
if uuid.startswith('uuid:Socket'):
return Switch(url=location, mac=mac,
rediscovery_enabled=rediscovery_enabled)
if uuid.startswith('uuid:Lightswitch'):
return LightSwitch(url=location, mac=mac,
rediscovery_enabled=rediscovery_enabled)
if uuid.startswith('uuid:Dimmer'):
return Dimmer(url=location, mac=mac,
rediscovery_enabled=rediscovery_enabled)
if uuid.startswith('uuid:Insight'):
return Insight(url=location, mac=mac,
rediscovery_enabled=rediscovery_enabled)
if uuid.startswith('uuid:Sensor'):
return Motion(url=location, mac=mac,
rediscovery_enabled=rediscovery_enabled)
if uuid.startswith('uuid:Maker'):
return Maker(url=location, mac=mac,
rediscovery_enabled=rediscovery_enabled)
"""Representation of a WeMo Insight device."""
import logging
from datetime import datetime
from .switch import Switch
LOG = logging.getLogger(__name__)
class Insight(Switch):
"""Representation of a WeMo Insight device."""
def __init__(self, *args, **kwargs):
"""Create a WeMo Switch device."""
Switch.__init__(self, *args, **kwargs)
self.insight_params = {}
self.update_insight_params()
def __repr__(self):
"""Return a string representation of the device."""
return ''.format(name=self.name)
def update_insight_params(self):
"""Get and parse the device attributes."""
# pylint: disable=maybe-no-member