def set_brightness(self, brightness: int): """Set brightness of dimmable bulb.""" if self.dimmable_feature: if brightness > 0 and brightness <= 100: body = helpers.req_body(self.manager, 'devicestatus') body['uuid'] = self.uuid body['status'] = 'on' body['brightNess'] = str(brightness) r, _ = helpers.call_api( '/SmartBulb/v1/device/updateBrightness', 'put', headers=helpers.req_headers(self.manager), json=body) if helpers.check_response(r, 'bulb_toggle'): self._brightness = brightness return True else: logger.debug('Error setting brightness for {}'.format( self.device_name)) return False else: logger.warning('Invalid brightness') return False else: logger.debug('%s is not dimmable', self.device_name)
def get_details(self): """Get details of tunable bulb.""" body = helpers.req_body(self.manager, 'bypass') body['cid'] = self.cid body['jsonCmd'] = {'getLightStatus': 'get'} body['configModule'] = self.config_module r, _ = helpers.call_api('/cloud/v1/deviceManaged/bypass', 'post', headers=helpers.req_headers(self.manager), json=body) if helpers.check_response(r, 'bypass'): if r.get('code') == 0 and r.get('result').get('light') is not None: light = r.get('result').get('light') self.connection_status = 'online' self.device_status = light.get('action', 'off') if self.dimmable_feature: self._brightness = light.get('brightness') if self.color_temp_feature: self._color_temp = light.get('colorTempe') elif r.get('code') == -11300027: logger.debug('%s device offline', self.device_name) self.connection_status = 'offline' self.device_status = 'off' else: logger.warning('%s - Unknown return code - %d with message %s', self.device_name, r.get('code'), r.get('msg')) else: logger.debug('Error getting {} details'.format(self.device_name))
def rgb_color_status(self, status: str, red: int = None, blue: int = None, green: int = None) -> bool: """Set faceplate RGB color.""" body = helpers.req_body(self.manager, 'devicestatus') body['status'] = status body['uuid'] = self.uuid head = helpers.req_headers(self.manager) if red is not None and blue is not None and green is not None: body['rgbValue'] = {'red': red, 'blue': blue, 'green': green} r, _ = helpers.call_api( '/dimmer/v1/device/devicergbstatus', 'put', headers=head, json=body ) if r is not None and helpers.check_response(r, 'walls_toggle'): self._rgb_status = status if body.get('rgbValue') is not None: self._rgb_value = {'red': red, 'blue': blue, 'green': green} return True else: logger.warning('Error turning {} off'.format(self.device_name)) return False
def set_brightness(self, brightness: int) -> bool: """Set brightness of tunable bulb.""" if self.dimmable_feature: if brightness > 0 and brightness <= 100: body = helpers.req_body(self.manager, 'bypass') body['cid'] = self.cid body['configModule'] = self.config_module if self.device_status == 'off': light_dict = {'action': 'on', 'brightness': brightness} else: light_dict = {'brightness': brightness} body['jsonCmd'] = {'light': light_dict} r, _ = helpers.call_api('/cloud/v1/deviceManaged/bypass', 'post', headers=helpers.req_headers( self.manager), json=body) if helpers.check_response(r, 'bypass'): if r.get('code') == 0: self._brightness = brightness return True else: self.device_status = 'off' self.connection_status = 'offline' logger.debug('%s offline', self.device_name) else: logger.debug('Error setting brightness for {}'.format( self.device_name)) else: logger.warning('Invalid brightness') else: logger.debug('%s is not dimmable', self.device_name) return False
def get_details(self): """Get 15A outlet details.""" body = helpers.req_body(self.manager, 'devicedetail') body['uuid'] = self.uuid r, _ = helpers.call_api( '/15a/v1/device/devicedetail', 'post', headers=helpers.req_headers(self.manager), json=body ) attr_list = ('deviceStatus', 'activeTime', 'energy', 'power', 'voltage', 'nightLightStatus', 'nightLightAutomode', 'nightLightBrightness') if (helpers.check_response(r, '15a_detail') and all(k in r for k in attr_list)): self.device_status = r.get('deviceStatus') self.connection_status = r.get('connectionStatus') self.details = helpers.build_details_dict(r) else: logger.debug( 'Unable to get {0} details'.format(self.device_name) )
def set_color_temp(self, color_temp: int) -> bool: """Set Color Temperature of Bulb in pct (1 - 100).""" if color_temp < 0 or color_temp > 100: logger.debug('Invalid color temperature - only between 0 and 100') return False body = helpers.req_body(self.manager, 'bypass') body['cid'] = self.cid body['jsonCmd'] = {'light': {}} if self.device_status == 'off': light_dict = {'action': 'on', 'colorTempe': color_temp} else: light_dict = {'colorTempe': color_temp} body['jsonCmd']['light'] = light_dict r, _ = helpers.call_api('/cloud/v1/deviceManaged/bypass', 'post', headers=helpers.req_headers(self.manager), json=body) if helpers.check_response(r, 'bypass'): if r.get('code') == -11300027: logger.debug('%s device offline', self.device_name) self.connection_status = 'offline' self.device_status = 'off' return False elif r.get('code') == 0: self.device_status = 'on' self._color_temp = color_temp return True else: logger.warning('%s - Unknown return code - %d with message %s', self.device_name, r.get('code'), r.get('msg')) return False
def get_config(self): """Get configuration and firmware info of tunable bulb.""" body = helpers.req_body(self.manager, 'bypass_config') body['uuid'] = self.uuid r, _ = helpers.call_api('/cloud/v1/deviceManaged/configurations', 'post', headers=helpers.req_headers(self.manager), json=body) if helpers.check_response(r, 'config'): self.config = helpers.build_config_dict(r)
def get_config(self): """Get configuration of dimmable bulb.""" body = helpers.req_body(self.manager, 'devicedetail') body['method'] = 'configurations' body['uuid'] = self.uuid r, _ = helpers.call_api('/SmartBulb/v1/device/configurations', 'post', headers=helpers.req_headers(self.manager), json=body) if helpers.check_response(r, 'config'): self.config = helpers.build_config_dict(r)
def get_yearly_energy(self): """Get 7A outlet yearly energy info and build yearly energy dict.""" r, _ = helpers.call_api( '/v1/device/' + self.cid + '/energy/year', 'get', headers=helpers.req_headers(self.manager) ) if r is not None and helpers.check_response(r, '7a_energy'): self.energy['year'] = helpers.build_energy_dict(r) else: logger.debug( 'Unable to get {0} yearly data'.format(self.device_name))
def get_config(self): """Get switch device configuration info.""" body = helpers.req_body(self.manager, 'devicedetail') body['method'] = 'configurations' body['uuid'] = self.uuid r, _ = helpers.call_api( '/inwallswitch/v1/device/configurations', 'post', headers=helpers.req_headers(self.manager), json=body) if helpers.check_response(r, 'config'): self.config = helpers.build_config_dict(r)
def turn_off_nightlight(self): """Turn Off Nightlight.""" body = helpers.req_body(self.manager, 'devicestatus') body['uuid'] = self.uuid body['mode'] = 'manual' response, _ = helpers.call_api( '/15a/v1/device/nightlightstatus', 'put', headers=helpers.req_headers(self.manager), json=body ) return helpers.check_response(response, '15a_ntlight')
def toggle(self, status): """Toggle dimmable bulb.""" body = helpers.req_body(self.manager, 'devicestatus') body['uuid'] = self.uuid body['status'] = status r, _ = helpers.call_api('/SmartBulb/v1/device/devicestatus', 'put', headers=helpers.req_headers(self.manager), json=body) if helpers.check_response(r, 'bulb_toggle'): self.device_status = status return True else: return False
def get_details(self): """Get details of dimmable bulb.""" body = helpers.req_body(self.manager, 'devicedetail') body['uuid'] = self.uuid r, _ = helpers.call_api('/SmartBulb/v1/device/devicedetail', 'post', headers=helpers.req_headers(self.manager), json=body) if helpers.check_response(r, 'bulb_detail'): self.connection_status = r.get('connectionStatus') self.device_status = r.get('deviceStatus') if self.dimmable_feature: self._brightness = int(r.get('brightNess')) else: logger.debug('Error getting {} details'.format(self.device_name))
def get_yearly_energy(self): """Get outdoor outlet yearly energy info and populate energy dict.""" body = helpers.req_body(self.manager, 'energy_year') body['uuid'] = self.uuid response, _ = helpers.call_api( '/outdoorsocket15a/v1/device/energyyear', 'post', headers=helpers.req_headers(self.manager), json=body ) if helpers.check_response(response, '10a_energy'): self.energy['year'] = helpers.build_energy_dict(response) else: logger.debug( 'Unable to get {0} yearly data'.format(self.device_name) )
def get_details(self): """Get 10A outlet details.""" body = helpers.req_body(self.manager, 'devicedetail') body['uuid'] = self.uuid r, _ = helpers.call_api( '/10a/v1/device/devicedetail', 'post', headers=helpers.req_headers(self.manager), json=body ) if helpers.check_response(r, '10a_detail'): self.device_status = r.get('deviceStatus', self.device_status) self.connection_status = r.get('connectionStatus', self.connection_status) self.details = helpers.build_details_dict(r) else: logger.debug('Unable to get {0} details'.format(self.device_name))
def turn_off(self): """Turn 15A outlet off - return True if successful.""" body = helpers.req_body(self.manager, 'devicestatus') body['uuid'] = self.uuid body['status'] = 'off' response, _ = helpers.call_api( '/15a/v1/device/devicestatus', 'put', headers=helpers.req_headers(self.manager), json=body ) if helpers.check_response(response, '15a_toggle'): self.device_status = 'off' return True else: logger.warning('Error turning {} off'.format(self.device_name)) return False
def turn_on(self): """Turn on switch device.""" body = helpers.req_body(self.manager, 'devicestatus') body['status'] = 'on' body['uuid'] = self.uuid head = helpers.req_headers(self.manager) r, _ = helpers.call_api( '/inwallswitch/v1/device/devicestatus', 'put', headers=head, json=body ) if r is not None and helpers.check_response(r, 'walls_toggle'): self.device_status = 'on' return True else: logger.warning('Error turning {} on'.format(self.device_name)) return False
def toggle(self, status): """Toggle tunable bulb.""" body = helpers.req_body(self.manager, 'bypass') body['cid'] = self.cid body['configModule'] = self.config_module body['jsonCmd'] = {'light': {'action': status}} r, _ = helpers.call_api('/cloud/v1/deviceManaged/bypass', 'post', headers=helpers.req_headers(self.manager), json=body) if helpers.check_response(r, 'bypass'): if r.get('code') == 0: self.device_status = status return True else: logger.debug('%s offline', self.device_name) self.device_status = 'off' self.connection_status = 'offline' return False
def get_details(self): """Get switch device details.""" body = helpers.req_body(self.manager, 'devicedetail') body['uuid'] = self.uuid head = helpers.req_headers(self.manager) r, _ = helpers.call_api( '/inwallswitch/v1/device/devicedetail', 'post', headers=head, json=body ) if r is not None and helpers.check_response(r, 'walls_detail'): self.device_status = r.get('deviceStatus', self.device_status) self.details['active_time'] = r.get('activeTime', 0) self.connection_status = r.get('connectionStatus', self.connection_status) else: logger.debug('Error getting {} details'.format(self.device_name))
def get_details(self): """Get 7A outlet details.""" r, _ = helpers.call_api( '/v1/device/' + self.cid + '/detail', 'get', headers=helpers.req_headers(self.manager) ) if r is not None and helpers.check_response(r, '7a_detail'): self.device_status = r.get('deviceStatus', self.device_status) self.details['active_time'] = r.get('activeTime', 0) self.details['energy'] = r.get('energy', 0) power = r.get('power', '0:0') power = round(float(helpers.calculate_hex(power)), 2) self.details['power'] = power voltage = r.get('voltage', '0:0') voltage = round(float(helpers.calculate_hex(voltage)), 2) self.details['voltage'] = voltage else: logger.debug('Unable to get {0} details'.format( self.device_name))
def toggle(self, status): """Toggle power for outdoor outlet.""" body = helpers.req_body(self.manager, 'devicestatus') body['uuid'] = self.uuid body['status'] = status body['switchNo'] = self.sub_device_no response, _ = helpers.call_api( '/outdoorsocket15a/v1/device/devicestatus', 'put', headers=helpers.req_headers(self.manager), json=body ) if helpers.check_response(response, 'outdoor_toggle'): self.device_status = status return True else: logger.warning( 'Error turning {} {}'.format(self.device_name, status)) return False
def get_details(self): """Get details for outdoor outlet.""" body = helpers.req_body(self.manager, 'devicedetail') body['uuid'] = self.uuid r, _ = helpers.call_api( '/outdoorsocket15a/v1/device/devicedetail', 'post', headers=helpers.req_headers(self.manager), json=body) if helpers.check_response(r, 'outdoor_detail'): self.details = helpers.build_details_dict(r) self.connection_status = r.get('connectionStatus') dev_no = self.sub_device_no sub_device_list = r.get('subDevices') if sub_device_list and dev_no <= len(sub_device_list): self.device_status = sub_device_list[(dev_no + -1)].get( 'subDeviceStatus') else: logger.debug('Unable to get {} details'.format(self.device_name))
def switch_toggle(self, status: str) -> bool: """Toggle switch status.""" if status not in ['on', 'off']: logger.debug('Invalid status passed to wall switch') return False body = helpers.req_body(self.manager, 'devicestatus') body['status'] = status body['uuid'] = self.uuid head = helpers.req_headers(self.manager) r, _ = helpers.call_api( '/dimmer/v1/device/devicestatus', 'put', headers=head, json=body ) if r is not None and helpers.check_response(r, 'walls_toggle'): self.device_status = status return True else: logger.warning('Error turning %s %s', self.device_name, status) return False
def get_details(self): """Get dimmer switch details.""" body = helpers.req_body(self.manager, 'devicedetail') body['uuid'] = self.uuid head = helpers.req_headers(self.manager) r, _ = helpers.call_api( '/dimmer/v1/device/devicedetail', 'post', headers=head, json=body) if r is not None and helpers.check_response(r, 'walls_detail'): self.device_status = r.get('deviceStatus', self.device_status) self.details['active_time'] = r.get('activeTime', 0) self.connection_status = r.get('connectionStatus', self.connection_status) self._brightness = r.get('brightness') self._rgb_status = r.get('rgbStatus') self._rgb_value = r.get('rgbValue') self._indicator_light = r.get('indicatorlightStatus') else: logger.debug('Error getting {} details'.format(self.device_name))
def set_brightness(self, brightness: int): """Set brightness of dimmer - 1 - 100.""" if isinstance(brightness, int) and \ (brightness > 0 or brightness <= 100): body = helpers.req_body(self.manager, 'devicestatus') body['brightness'] = brightness body['uuid'] = self.uuid head = helpers.req_headers(self.manager) r, _ = helpers.call_api( '/dimmer/v1/device/updatebrightness', 'put', headers=head, json=body) if r is not None and helpers.check_response(r, 'walls_toggle'): self._brightness = brightness return True else: logger.warning('Error setting %s brightness', self.device_name) else: logger.warning('Invalid brightness') return False