Example #1
0
    def __init__(self, adapter, _id, vesync_dev):
        """
        Initialize the object.

        adapter -- the Adapter managing this device
        _id -- ID of this device
        vesync_dev -- the vesync device object to initialize from
        """
        Device.__init__(self, adapter, _id)

        self.vesync_dev = vesync_dev
        self.name = vesync_dev.device_name
        self.description = vesync_dev.device_type
        if not self.name:
            self.name = self.description

        # All devices have this property
        self.properties['on'] = EtekcitySwitchProperty(
            self,
            'on',
            {
                '@type': 'OnOffProperty',
                'title': 'On/Off',
                'type': 'boolean',
            },
            self.on)

        t = threading.Thread(target=self.poll)
        t.daemon = True
        t.start()
    def __init__(self, adapter):
        """
        Initialize the object.
        adapter -- the Adapter managing this device
        """

        Device.__init__(self, adapter, 'display-toggle')

        self._id = 'display-toggle'
        self.id = 'display-toggle'
        self.adapter = adapter

        self.name = 'Display'
        self.title = 'Display'
        self.description = 'Turn the display on and off'

        self._type = ['OnOffSwitch']

        try:

            self.properties["signal"] = DisplayToggleProperty(
                self, "signal", {
                    '@type': 'OnOffProperty',
                    'label': "Signal",
                    'type': 'boolean'
                }, True)  # set the display to on at init

        except Exception as ex:
            print("error adding properties: " + str(ex))

        print("Display toggle thing has been created.")
    def __init__(self, adapter, api_handler, device_name, device_title,
                 device_type):
        """
        Initialize the object.
        adapter -- the Adapter managing this device
        """

        Device.__init__(self, adapter, device_name)
        #print("Creating PrivacyManager thing")

        self._id = device_name
        self.id = device_name
        self.adapter = adapter
        self.api_handler = api_handler
        self._type.append(device_type)
        #self._type = ['OnOffSwitch']

        self.name = device_name
        self.title = device_title
        self.description = 'Control devices via via the internet'

        #if self.adapter.DEBUG:
        #print("Empty PrivacyManager thing has been created. device_name = " + str(self.name))
        #print("new thing's adapter = " + str(self.adapter))

        #print("self.api_handler.persistent_data['enabled'] = " + str(self.api_handler.persistent_data['enabled']))

        self.properties["data-deletion"] = PrivacyManagerProperty(
            self, "data-deletion", {
                '@type': 'OnOffProperty',
                'title': "Data deletion",
                'type': 'boolean',
                'readOnly': False,
            }, False)
        """
Example #4
0
    def __init__(self, adapter, _id, address, p100, info):
        """
        Initialize the object.

        adapter -- the Adapter managing this device
        _id -- ID of this device
        address -- IP address
        p100 -- the P100 object to initialize from
        info -- the device info object
        """
        Device.__init__(self, adapter, _id)
        self._type = ['OnOffSwitch', 'SmartPlug']

        self.address = address
        self.p100 = p100
        self.description = info['model']

        if 'nickname' in info and len(info['nickname']) > 0:
            self.name = base64.b64decode(info['nickname']).decode('utf8')
        else:
            self.name = self.description

        self.properties['on'] = TapoProperty(self, 'on', {
            '@type': 'OnOffProperty',
            'title': 'On/Off',
            'type': 'boolean',
        }, self.is_on(info))

        t = threading.Thread(target=self.poll)
        t.daemon = True
        t.start()
Example #5
0
    def __init__(self, adapter, _id, ip_address, pin):
        Device.__init__(self, adapter, _id)

        self.description = "Arduino device"
        self.name = _id
        self.pin = pin
        self.ip = ip_address
Example #6
0
    def __init__(self, adapter, _id, sengled_dev):
        """
        Initialize the object.

        adapter -- the Adapter managing this device
        _id -- ID of this device
        sengled_dev -- the sengled device object to initialize from
        """
        Device.__init__(self, adapter, _id)
        self._type = ['OnOffSwitch', 'Light']
        self.type = 'onOffLight'

        self.sengled_dev = sengled_dev
        self.name = sengled_dev.name
        self.description = sengled_dev.type_code
        if not self.name:
            self.name = self.description

        self.properties['on'] = SengledProperty(self, 'on', {
            '@type': 'OnOffProperty',
            'title': 'On/Off',
            'type': 'boolean',
        }, self.on)

        self.properties['level'] = SengledProperty(
            self, 'level', {
                '@type': 'BrightnessProperty',
                'title': 'Brightness',
                'type': 'integer',
                'unit': 'percent',
                'minimum': 0,
                'maximum': 100,
            }, self.level)

        self.sengled_dev.set_attribute_update_callback(self.update_property)
Example #7
0
    def __init__(self, adapter, _id, dev_id, light):
        """
        adapter -- the Adapter for this device
        _id -- ID of this device
        dev_id -- id on the conbee device
        light -- device info from deconz - ConBee request
        """
        Device.__init__(self, adapter, _id)
        self.etag = ''
        self.poll_interval = 2
        self.reachable = None

        self.dev_id = dev_id
        self.light = light
        if 'name' in light.keys() and len(light['name']) > 0:
            self.name = light['name']
        else:
            self.name = light['manufacturername']
        self.description = light['manufacturername'] + ' / ' + light['type']
        self.add_property(ReachableProperty(self, self.is_reachable()))

        self.active_poll = True
        self.thread = threading.Thread(target=self.poll)
        self.thread.daemon = True
        self.thread.start()
Example #8
0
    def __init__(self, adapter, _id, name, details):
        """
        Initialize the object.

        adapter -- the Adapter managing this device
        _id -- ID of this device
        name -- The name for this device
        index -- index inside parent device
        """

        #Device.__init__(self, adapter, 'presence-{}'.format(mac))
        Device.__init__(self, adapter, _id)

        self.adapter = adapter
        self.name = name
        self.description = "A device on the local network"
        self._id = _id
        self._type = ['BinarySensor']
        #self.properties = {}
        #print("device self.properties at init: " + str(self.properties))
        #self.connected_notify(True)

        self.properties['details'] = PresenceProperty(self, 'details', {
            'label': 'Details',
            'type': 'string',
            'readOnly': True,
        }, str(details))

        if self.adapter.DEBUG:
            print("+ Adding new device: " + str(name))
    def __init__(self, adapter, _id, dev_dict):
        """
        Initialize the object.

        adapter -- the Adapter managing this device
        _id -- ID of this device
        dev_dict -- the device object to initialize from
        """
        Device.__init__(self, adapter, _id)
        self.sensor = dev_dict['sensor']
        self._type = ['OnOffSwitch', 'Light Sensor']

        if not self.name:
            self.name = self.description

        self.update_properties()

        self.properties['on'] = TSL2561Property(self, 'on', {
            '@type': 'OnOffProperty',
            'label': 'On/Off',
            'type': 'boolean',
        }, self.is_on())

        self.properties['on'] = TSL2561Property(
            self, 'on', {
                '@type': 'ThresholdProperty',
                'label': 'Threshold in Lux',
                'type': 'number',
            }, _DEFAULT_THRESHOLD)

        t = threading.Thread(target=self.poll)
        t.daemon = True
        t.start()
Example #10
0
    def __init__(self, adapter, _id, hs100_dev, index=-1):
        """
        Initialize the object.

        adapter -- the Adapter managing this device
        _id -- ID of this device
        hs100_dev -- the pyHS100 device object to initialize from
        index -- index inside parent device
        """
        Device.__init__(self, adapter, _id)
        self._type = []

        self.hs100_dev = hs100_dev
        self.index = index
        self.description = hs100_dev.sys_info['model']

        if index >= 0:
            self.name = hs100_dev.sys_info['children'][index]['alias']
        else:
            self.name = hs100_dev.sys_info['alias']

        if not self.name:
            self.name = self.description

        t = threading.Thread(target=self.poll)
        t.daemon = True
        t.start()
    def __init__(self, adapter, _id, name, eufy_dev):
        """
        Initialize the object.

        adapter -- the Adapter managing this device
        _id -- ID of this device
        name -- name of this device
        eufy_dev -- the lakeside device object to initialize from
        """
        Device.__init__(self, adapter, _id)
        self._type = []

        self.eufy_dev = eufy_dev
        self.description = eufy_dev.kind
        self.name = name
        if not self.name:
            self.name = self.description

        try:
            self.eufy_dev.connect()
            self.eufy_dev.update()
        except OSError:
            pass

        t = threading.Thread(target=self.poll)
        t.daemon = True
        t.start()
Example #12
0
    def __init__(self, adapter, _id, dev, index=-1):
        """
        Initialize the object.

        adapter -- the Adapter managing this device
        _id -- ID of this device
        hs100_dev -- the pyHS100 device object to initialize from
        index -- index inside parent device
        """
        Device.__init__(self, adapter, _id)
        self.dev = dev
        self.index = index
        self._type.extend(['SnapClient Player'])
        self.mac = dev["host"]["mac"] if "host" in dev and "mac" in dev["host"] else False
        self.description = dev["host"]["ip"] if "host" in dev and "ip" in dev["host"] else "unknown"
        self.name = dev["host"]["name"] if "host" in dev and "name" in dev["host"] else self.description
        # connected = dev["connected"] if "connected" in dev else False
        # muted = dev["config"]["volume"]["muted"] if "config" in dev and "volume" in dev["config"] and "muted" in dev["config"]["volume"] else False
        # volume = dev["config"]["volume"]["percent"] if "config" in dev and "volume" in dev["config"] and "percent" in dev["config"]["volume"] else 0
        # sysinfo = dev["host"] if "host" in dev else {}

        self.properties['level'] = SnapClientProperty(
            self,
            'level',
            {
                '@type': 'VolumeProperty',
                'title': 'Volume',
                'type': 'integer',
                'unit': 'percent',
                'minimum': 0,
                'maximum': 100,
            },
            self.volume(dev)
        )

        self.properties['muted'] = SnapClientProperty(
            self,
            'muted',
            {
                '@type': 'OnOffProperty',
                'title': 'Mute',
                'type': 'boolean',
            },
            self.is_muted(dev)
        )

        self.properties['active'] = SnapClientProperty(
            self,
            'active',
            {
                '@type': 'BooleanProperty',
                'title': 'Active',
                'type': 'boolean',
                'readOnly': True
            },
            self.is_active(dev)
        )
Example #13
0
    def __init__(self, adapter, _id):
        Device.__init__(self, adapter, _id)

        self.description = _id + " desc"
        self.name = _id + " name"

        t = threading.Thread(target=self.poll)
        t.daemon = True
        t.start()
Example #14
0
 def __init__(self, adapter, scan_entry):
     Device.__init__(self, adapter, scan_entry.addr)
     self.name = 'Switchmate {}'.format(scan_entry.addr)
     self._type.append('OnOffSwitch')
     on = switchmate.get_scan_entry_status(scan_entry)
     self.properties['on'] = SwitchmateProperty(self, 'on', {
         '@type': 'OnOffProperty',
         'label': 'On/Off',
         'type': 'boolean'
     }, on)
Example #15
0
    def __init__(self, adapter, _id, ip, token):
        """
        Initialize the object.
        adapter -- the Adapter managing this device
        _id -- ID of this device
        ip -- ip address for this device
        token --token  for this device
        """
        from miio.philips_bulb import PhilipsBulb
        Device.__init__(self, adapter, _id)
        self._type = ['OnOffSwitch', 'Light', 'ColorControl']
        self.bulb = PhilipsBulb(ip=ip, token=token)

        self.update_properties()

        self.properties['colorTemperature'] = PhilipsBulbProperty(
            self, 'colorTemperature', {
                '@type': 'ColorTemperatureProperty',
                'label': 'Color Temperature',
                'type': 'integer',
                'unit': 'kelvin',
                'minimum': 1,
                'maximum': 100,
            }, self.color_temperature())

        self.properties['level'] = PhilipsBulbProperty(
            self, 'level', {
                '@type': 'BrightnessProperty',
                'label': 'Brightness',
                'type': 'integer',
                'unit': 'percent',
                'minimum': 1,
                'maximum': 100,
            }, self.brightness())

        self.properties['on'] = PhilipsBulbProperty(self, 'on', {
            '@type': 'OnOffProperty',
            'label': 'On/Off',
            'type': 'boolean',
        }, self.is_on())

        self.properties['scene'] = PhilipsBulbProperty(
            self, 'scene', {
                '@type': 'SceneProperty',
                'label': 'scene',
                'type': 'integer',
                'minimum': 1,
                'maximum': 4,
            }, self.scence())

        t = threading.Thread(target=self.poll)
        t.daemon = True
        t.start()
Example #16
0
    def __init__(self, adapter, _id, pin, config):
        """Initialize the object.

        adapter -- the Adapter managing this device
        _id -- ID to assign to this device
        pin -- the pin the device is attached to
        config -- the device config
        """
        Device.__init__(self, adapter, _id)
        self._type = ['TemperatureSensor', 'MultiLevelSensor']
        self.name = 'DHT22 ({})'.format(pin)
        self.description = 'DHT22 sensor on pin {}'.format(pin)

        self.sensor_type = Adafruit_DHT.DHT22
        self.pin = pin
        self.temperature_offset = config['temperature_offset']
        self.humidity_offset = config['humidity_offset']

        humidity, temperature = \
            Adafruit_DHT.read_retry(self.sensor_type, self.pin)

        self.properties['temperature'] = DHT22Property(
            self,
            'temperature',
            {
                '@type': 'TemperatureProperty',
                'title': 'Temperature',
                'type': 'number',
                'readOnly': True,
                'unit': 'degree celsius',
            },
            self.pin,
            temperature
        )

        self.properties['humidity'] = DHT22Property(
            self,
            'humidity',
            {
                '@type': 'LevelProperty',
                'title': 'Humidity',
                'type': 'number',
                'readOnly': True,
                'unit': 'percent',
            },
            self.pin,
            humidity
        )

        t = threading.Thread(target=self.poll)
        t.daemon = True
        t.start()
Example #17
0
    def __init__(self, adapter, audio_output_list, video_audio_output_list):
        """
        Initialize the object.
        adapter -- the Adapter managing this device
        """

        Device.__init__(self, adapter, 'airport')

        self._id = 'airport'
        self.id = 'airport'
        self.adapter = adapter

        self.name = 'Airport'
        self.title = 'Airport'
        self.description = 'Airport streaming'
        #self._type = ['MultiLevelSwitch']
        #self.connected = False

        self.audio_output_list = audio_output_list
        self.video_audio_output_list = video_audio_output_list

        try:
            if self.adapter.audio:
                self.properties["audio output"] = AirportProperty(
                                self,
                                "audio output",
                                {
                                    'label': "Audio-only output",
                                    'type': 'string',
                                    'enum': audio_output_list,
                                },
                                self.adapter.persistent_data['audio_output'])

            if self.adapter.video:
                self.properties["video audio output"] = AirportProperty(
                                self,
                                "video audio output",
                                {
                                    'label': "Video audio output",
                                    'type': 'string',
                                    'enum': video_audio_output_list,
                                },
                                self.adapter.persistent_data['video_audio_output'])


        except Exception as ex:
            print("error adding properties: " + str(ex))

        print("Airport thing has been created.")
Example #18
0
    def __init__(self, adapter, device_address, channel_number, title=""):
        """
        Initialize the object.
        adapter -- the Adapter managing this device
        _id -- ID of this device
        hs100_dev -- the pyHS100 device object to initialize from
        index -- index inside parent device
        """

        self._device_address = device_address
        device_id = device_address + channel_number
        Device.__init__(self, adapter, device_id)
        if title == "":
            self.title = self._type[0] + device_id
        self._channel_number = channel_number
Example #19
0
    def __init__(self, adapter, _id, provider, poll_interval, server_id):
        """
        Initialize the object.

        adapter -- the Adapter managing this device
        _id -- ID of this device
        provider -- the data provider
        poll_interval -- interval at which to poll the provider, in minutes
        server_id -- ID of server to use (for speedtest.net)
        """
        Device.__init__(self, adapter, _id)
        self._type = ['MultiLevelSensor']
        self.type = 'multiLevelSensor'

        self.provider = provider
        self.poll_interval = poll_interval
        self.server_id = server_id

        self.name = 'Internet speed test'
        self.description = 'Internet speed test'

        self.properties['download'] = Property(
            self,
            'download',
            {
                '@type': 'LevelProperty',
                'title': 'Download Speed',
                'type': 'integer',
                'unit': 'Mbps',
                'minimum': 0,
                'maximum': 10000,  # 10 Tbps... had to have something here
                'readOnly': True,
            })
        self.properties['download'].set_cached_value(0)

        self.links = [
            {
                'rel': 'alternate',
                'mediaType': 'text/html',
                'href': 'https://{}'.format(self.provider),
            },
        ]

        t = threading.Thread(target=self.poll)
        t.daemon = True
        t.start()
Example #20
0
    def __init__(self, adapter, _id, name, details):
        """
        Initialize the object.

        adapter -- the Adapter managing this device
        _id -- ID of this device
        name -- The name for this device
        index -- index inside parent device
        """

        #Device.__init__(self, adapter, 'presence-{}'.format(mac))
        Device.__init__(self, adapter, _id)

        self.adapter = adapter
        self.name = name
        self.description = "A device on the local network"
        self._id = _id
        #print("init " + str(self._id))
        self._type = ['BinarySensor']
        #self.properties = {}
        #print("device self.properties at init: " + str(self.properties))
        #self.connected_notify(True)

        self.last_add_mute_time = 0
        self.mute_until = 0

        self.properties['details'] = PresenceProperty(self, 'details', {
            'title': 'Details',
            'type': 'string',
            'readOnly': True,
        }, str(details))

        if self.adapter.DEBUG:
            print("+ Adding new device: " + str(name))

        action_meta = {
            "toggle": {
                "@type": "ToggleAction",
                "title": "Toggle",
                "description": "Toggggle"
            }
        }
        self.add_action("Data mute", action_meta)
Example #21
0
    def __init__(self, adapter, _id, addr, name):
        """
        Initialize the object.

        adapter -- the Adapter managing this device
        _id -- ID of this device
        addr -- the BT address to detect
        name -- name of the BT device with the addr
        """
        Device.__init__(self, adapter, _id)

        self.addr = addr
        self.name = name
        self.type = 'binarySensor'
        self.properties['on'] = BluetoothPresenceProperty(self, False)

        t = threading.Thread(target=self.poll)
        t.daemon = True
        t.start()
Example #22
0
    def __init__(self, handler, adapter, device_name, device_title, device_type):
        """
        Initialize the object.
        adapter -- the Adapter managing this device
        """

        
        Device.__init__(self, adapter, device_name)
        #print("Creating Highlight thing")
        
        self._id = device_name
        self.id = device_name
        self.adapter = adapter
        self.handler = handler
        self._type.append(device_type)

        self.name = device_name
        self.title = device_title
        self.description = 'Highlight device'
Example #23
0
    def __init__(self, adapter, _id, lifxlan_dev):
        """
        Initialize the object.

        adapter -- the Adapter managing this device
        _id -- ID of this device
        lifxlan_dev -- the lifxlan device object to initialize from
        """
        Device.__init__(self, adapter, _id)
        self._type = []

        self.lifxlan_dev = lifxlan_dev
        self.description = lifxlan_dev.get_product_name()
        self.name = lifxlan_dev.get_label()
        if not self.name:
            self.name = self.description

        self.t = threading.Thread(target=self.poll)
        self.t.daemon = True
        self.t.start()
Example #24
0
    def __init__(self, adapter, _id, wemo_dev):
        """
        Initialize the object.

        adapter -- the Adapter managing this device
        _id -- ID of this device
        wemo_dev -- the wemo device object to initialize from
        """
        Device.__init__(self, adapter, _id)
        self._type = []

        self.wemo_dev = wemo_dev
        self.description = wemo_dev.model
        self.name = wemo_dev.name

        self.wemo_dev.update_binary_state()

        t = threading.Thread(target=self.poll)
        t.daemon = True
        t.start()
Example #25
0
    def __init__(self, adapter):
        """
        Initialize the object.
        adapter -- the Adapter managing this device
        """

        Device.__init__(self, adapter, 'p1-device')
        #print("Creating P1 thing")

        self._id = 'p1-device'
        self.id = 'p1-device'
        self.adapter = adapter
        self._type.append('MultiLevelSensor')

        self.name = 'p1-device'
        self.title = 'Energy sensor'
        self.description = 'P1 Energy use sensor'

        if self.adapter.DEBUG:
            print("Empty P1 thing has been created.")
Example #26
0
    def __init__(self, adapter, _id, hs100_dev, sysinfo):
        """
        Initialize the object.

        adapter -- the Adapter managing this device
        _id -- ID of this device
        hs100_dev -- the pyHS100 device object to initialize from
        sysinfo -- current sysinfo dict for the device
        """
        Device.__init__(self, adapter, _id)
        self._type = []

        self.hs100_dev = hs100_dev
        self.description = sysinfo['model']
        self.name = sysinfo['alias']
        if not self.name:
            self.name = self.description

        t = threading.Thread(target=self.poll)
        t.daemon = True
        t.start()
Example #27
0
    def __init__(self, adapter, _id, meross_dev, channel=None):
        """
        Initialize the object.

        adapter -- the Adapter managing this device
        _id -- ID of this device
        meross_dev -- the meross device object to initialize from
        channel -- the channel index of this plug
        """
        Device.__init__(self, adapter, _id)

        self.meross_dev = meross_dev
        self.name = meross_dev.name
        self.description = meross_dev.type
        if not self.name:
            self.name = self.description

        if channel is not None:
            self.channel = channel
            self.name = '{} ({})'.format(self.name, channel)
        else:
            self.channel = 0
Example #28
0
    def __init__(self, adapter, _id, dev_dict):
        """
        Initialize the object.

        adapter -- the Adapter managing this device
        _id -- ID of this device
        dev_dict -- the device object to initialize from
        """
        Device.__init__(self, adapter, _id)
        self._type = ['OnOffSwitch', 'Light']

        self.bulb = Bulb(dev_dict['ip'])
        self.description = dev_dict['capabilities']['model']
        self.name = dev_dict['capabilities']['name']
        if not self.name:
            self.name = self.description

        self.support = dev_dict['capabilities']['support'].split(' ')

        self.update_properties()

        if self.is_color():
            self._type.append('ColorControl')

            self.properties['color'] = YeelightProperty(
                self, 'color', {
                    '@type': 'ColorProperty',
                    'label': 'Color',
                    'type': 'string',
                }, self.color())
        elif self.is_variable_color_temp():
            self._type.append('ColorControl')

            self.properties['colorTemperature'] = YeelightProperty(
                self, 'colorTemperature', {
                    '@type': 'ColorTemperatureProperty',
                    'label': 'Color Temperature',
                    'type': 'integer',
                    'unit': 'kelvin',
                    'minimum': 1700,
                    'maximum': 6500,
                }, self.color_temp())

        if self.is_dimmable() and not self.is_color():
            self.properties['level'] = YeelightProperty(
                self, 'level', {
                    '@type': 'BrightnessProperty',
                    'label': 'Brightness',
                    'type': 'integer',
                    'unit': 'percent',
                    'minimum': 0,
                    'maximum': 100,
                }, self.brightness())

        self.properties['on'] = YeelightProperty(self, 'on', {
            '@type': 'OnOffProperty',
            'label': 'On/Off',
            'type': 'boolean',
        }, self.is_on())

        if self.is_color():
            self.type = 'onOffColorLight'
        elif self.is_variable_color_temp():
            if self.is_dimmable():
                self.type = 'dimmableColorLight'
            else:
                self.type = 'onOffColorLight'
        elif self.is_dimmable():
            self.type = 'dimmableLight'
        else:
            self.type = 'onOffLight'

        t = threading.Thread(target=self.poll)
        t.daemon = True
        t.start()
Example #29
0
    def __init__(self, adapter, _id, station_id, unit):
        """
        Initialize the object.

        adapter -- the Adapter managing this device
        _id -- ID of this device
        station_id -- the NOAA station ID
        unit -- the unit to use, either english or metric
        """
        Device.__init__(self, adapter, _id)
        self._type = []

        self.station_id = station_id
        self.unit = unit

        self.get_station_info()

        self.high_tides = []
        self.low_tides = []

        if self.have_tide_predictions:
            self.properties['lowTideTime'] = TideCalendarProperty(
                self,
                'lowTideTime',
                {
                    'title': 'Low Tide Time',
                    'type': 'string',
                    'readOnly': True,
                },
                ''
            )

            self.properties['lowTideLevel'] = TideCalendarProperty(
                self,
                'lowTideLevel',
                {
                    'title': 'Low Tide Level',
                    'type': 'number',
                    'unit': 'foot' if self.unit == 'english' else 'meter',
                    'multipleOf': 0.1,
                    'readOnly': True,
                },
                0
            )

            self.properties['lowTide'] = TideCalendarProperty(
                self,
                'lowTide',
                {
                    'title': 'Low Tide',
                    'type': 'boolean',
                    'readOnly': True,
                },
                False
            )

            self.properties['highTideTime'] = TideCalendarProperty(
                self,
                'highTideTime',
                {
                    'title': 'High Tide Time',
                    'type': 'string',
                    'readOnly': True,
                },
                ''
            )

            self.properties['highTideLevel'] = TideCalendarProperty(
                self,
                'highTideLevel',
                {
                    'title': 'High Tide Level',
                    'type': 'number',
                    'unit': 'foot' if self.unit == 'english' else 'meter',
                    'multipleOf': 0.1,
                    'readOnly': True,
                },
                0
            )

            self.properties['highTide'] = TideCalendarProperty(
                self,
                'highTide',
                {
                    'title': 'High Tide',
                    'type': 'boolean',
                    'readOnly': True,
                },
                False
            )

            self.properties['status'] = TideCalendarProperty(
                self,
                'status',
                {
                    'title': 'Status',
                    'type': 'string',
                    'enum': [
                        'low',
                        'high',
                        'rising',
                        'falling',
                    ],
                    'readOnly': True,
                },
                ''
            )

        if self.have_water_levels:
            self._type = ['MultiLevelSensor']
            self.properties['currentLevel'] = TideCalendarProperty(
                self,
                'currentLevel',
                {
                    'title': 'Current Level',
                    '@type': 'LevelProperty',
                    'type': 'number',
                    'unit': 'foot' if self.unit == 'english' else 'meter',
                    'multipleOf': 0.1,
                    'minimum': -50 if self.unit == 'english' else -15.2,
                    'maximum': 50 if self.unit == 'english' else 15.2,
                    'readOnly': True,
                },
                0
            )

        self.links = [
            {
                'rel': 'alternate',
                'mediaType': 'text/html',
                'href': 'https://tidesandcurrents.noaa.gov/noaatidepredictions.html?id={}'.format(self.station_id),  # noqa
            },
        ]

        t = threading.Thread(target=self.poll)
        t.daemon = True
        t.start()

        t = threading.Thread(target=self.check_events)
        t.daemon = True
        t.start()
Example #30
0
    def __init__(self, adapter):
        """
        Initialize the object.

        adapter -- the Adapter managing this device
        """
        Device.__init__(self, adapter, 'awox-mesh-light')
        self.id = self._id = 'awox-mesh-light'
        self.adapter = adapter
        self.controller = adapter.controller
        if _DEBUG:
            print("info: connecting: address=%s" % self.controller.mac)
        self.controller.connect()
        if _DEBUG:
            print("info: connected: model=%s" % self.controller.getModelNumber())

        self.name = 'AwoxMeshLight'
        self.description = 'Expose AwoxMeshLight actuators'
        self.links = [
            {
                'rel': 'alternate',
                'mediaType': 'text/html',
                'href': adapter.URL
            }
        ]
        self._type = ['OnOffSwitch', 'MultiLevelSwitch', 'Light', 'ColorControl']

        try:
            self.properties['on'] = AwoxMeshLightProperty(
                self,
                "on",
                {
                    '@type': 'OnOffProperty',
                    'label': "Switch",
                    'type': 'boolean',
                    'description': 'Whether the lamp is turned on',
                },
                True)
            self.controller.on()

            self.properties['brightness'] = AwoxMeshLightProperty(
                self,
                "brightness",
                {
                    '@type': 'BrightnessProperty',
                    'label': 'Brightness',
                    'type': 'number',
                    'description': 'The level of light from 0-100',
                    'minimum': 0,
                    'maximum': 100,
                    'unit': 'percent'
                },
                100)
            self.controller.setColorBrightness(100)

            self.properties['color'] = AwoxMeshLightProperty(
                self,
                "color",
                {
                    '@type': 'ColorProperty',
                    'label': "Color",
                    'type': 'string',
                    'readOnly': False
                },
                '#ffffff')
            self.controller.setColor(0xFF, 0xFF, 0xFF)

            self.add_action(
                'cold',
                {
                    'title': 'Cold White'
                }
            )
            self.add_action(
                'warm',
                {
                    'title': 'Warm White'
                }
            )

            self.add_action(
                'random',
                {
                    'title': 'Random Color',
                }
            )
            self.add_action(
                'preset',
                {
                    'title': 'Fading preset',
                    'input': {
                        'type': 'object',
                        'required': [
                            'preset',
                        ],
                        'properties': {
                            'preset': {
                                'type': 'integer',
                                'default': 0,
                                'maximum': 6,
                                'minimum': 0
                            }
                        }
                    }
                }
            )
            self.pairing = True

        except Exception as ex:
            print("error: Adding properties: " + str(ex))