Beispiel #1
0
    def configure_light(self, onoff=None, rgb=None, luminance=100, temperature=-1, gradual=0, channel=0):
        if rgb is not None and temperature != -1:
            l.error("You are trying to set both RGB and luminance values for this bulb. It won't work!")

        # Prepare a basic payload
        payload = {
            'light': {
                'channel': channel,
                'gradual': gradual
            }
        }

        if onoff is not None:
            payload['light']['onoff'] = onoff

        mode = 0
        if self.supports_mode(MODE_RGB) and rgb is not None:
            # Convert the RGB to integer
            color = to_rgb(rgb)
            payload['light']['rgb'] = color
            mode = mode | MODE_RGB

        if self.supports_mode(MODE_LUMINANCE) and luminance != -1:
            payload['light']['luminance'] = luminance
            mode = mode | MODE_LUMINANCE

        if self.supports_mode(MODE_TEMPERATURE) and temperature != -1:
            payload['light']['temperature'] = temperature
            mode = mode | MODE_TEMPERATURE

        payload['light']['capacity'] = mode
        self.execute_command(command='SET', namespace=LIGHT, payload=payload)
Beispiel #2
0
    def turn_on(self, **kwargs) -> None:
        self._device.turn_on(channel=self._channel_id)
        rgb = self._device.get_light_color(self._channel_id).get('rgb')
        brightness = self._device.get_light_color(self._channel_id).get('luminance')

        if 'hs_color' in kwargs:
            h, s = kwargs['hs_color']
            r, g, b = colorsys.hsv_to_rgb(h/360, s/100, 255)
            rgb = to_rgb((int(r), int(g), int(b)))
        elif 'brightness' in kwargs:
            brightness = kwargs['brightness'] / 255 * 100

        self._device.set_light_color(self._channel_id, rgb=rgb, luminance=brightness)
 def event_handler(self, eventobj):
     logging.debug("Event : {}".format(eventobj.event_type))
     if eventobj.event_type == MerossEventType.DEVICE_SWITCH_STATUS:
         self.send({
             'action': 'switch',
             'uuid': eventobj.device.uuid,
             'channel': eventobj.channel_id,
             'status': int(eventobj.switch_state)
         })
     elif eventobj.event_type == MerossEventType.DEVICE_ONLINE_STATUS:
         self.send({
             'action': 'online',
             'uuid': eventobj.device.uuid,
             'status': eventobj.status
         })
     elif eventobj.event_type == MerossEventType.DEVICE_BULB_SWITCH_STATE:
         self.send({
             'action': 'switch',
             'uuid': eventobj.device.uuid,
             'channel': eventobj.channel,
             'status': int(eventobj.is_on)
         })
     elif eventobj.event_type == MerossEventType.DEVICE_BULB_STATE:
         self.send({
             'action': 'bulb',
             'uuid': eventobj.device.uuid,
             'channel': eventobj.channel,
             'status': eventobj.light_state
         })
     elif eventobj.event_type == MerossEventType.GARAGE_DOOR_STATUS:
         self.send({
             'action': 'door',
             'uuid': eventobj.device.uuid,
             'channel': eventobj.channel,
             'status': eventobj.door_state
         })
     #HUMIDIFIER
     elif eventobj.event_type == MerossEventType.HUMIDIFIER_LIGHT_EVENT:
         self.send({
             'action': 'hlight',
             'uuid': eventobj.device.uuid,
             'channel': eventobj.channel,
             'status': int(eventobj.is_on),
             'rgb': int(to_rgb(eventobj.rgb)),
             'luminance': eventobj.luminance
         })
     elif eventobj.event_type == MerossEventType.HUMIDIFIER_SPRY_EVENT:
         self.send({
             'action': 'hspray',
             'uuid': eventobj.device.uuid,
             'channel': eventobj.channel,
             'status': int(eventobj.spry_mode.value)
         })
     #ADDITIONS
     elif eventobj.event_type == MerossEventType.CLIENT_CONNECTION:
         self.send({'action': 'connect', 'status': eventobj.status.value})
     elif eventobj.event_type == MerossEventType.DEVICE_BIND:
         self.send({
             'action': 'bind',
             'uuid': eventobj.device.uuid,
             'data': eventobj.bind_data
         })
     elif eventobj.event_type == MerossEventType.DEVICE_UNBIND:
         self.send({'action': 'unbind', 'uuid': eventobj.device.uuid})