Ejemplo n.º 1
0
 def get_details(self) -> None:
     """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_object=body,
     )
     if not isinstance(r, dict) or not helpers.code_check(r):
         logger.debug('Error calling %s', self.device_name)
         return
     response = r
     if response.get('result', {}).get('light') is not None:
         light = response.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 response.get('code') == -11300027:
         logger.debug('%s device offline', self.device_name)
         self.connection_status = 'offline'
         self.device_status = 'off'
     else:
         logger.debug(
             '%s - Unknown return code - %d with message %s',
             self.device_name,
             response.get('code'),
             response.get('msg'),
         )
Ejemplo n.º 2
0
    def login(self) -> bool:
        """Return True if log in request succeeds"""
        user_check = isinstance(self.username, str) and len(self.username) > 0
        pass_check = isinstance(self.password, str) and len(self.password) > 0

        if user_check and pass_check:
            response, _ = helpers.call_api('/cloud/v1/user/login',
                                           'post',
                                           json=helpers.req_body(
                                               self, 'login'))

            if response and helpers.check_response(response, 'login'):
                self.token = response['result']['token']
                self.account_id = response['result']['accountID']
                self.enabled = True

                return True
            else:
                logger.error('Error logging in with username and password')
                return False

        else:
            if user_check is False:
                logger.error('Username invalid')
            if pass_check is False:
                logger.error('Password invalid')

        return False
Ejemplo n.º 3
0
    def get_details(self):
        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)
            )
Ejemplo n.º 4
0
    def test_login(self):
        mock_vesync = mock.Mock()
        mock_vesync.login.return_value = True
        self.assertTrue(mock_vesync.login())
        mock_vesync.login.return_value = False
        self.assertFalse(mock_vesync.login())

        with patch('pyvesync.helpers.Helpers.call_api') as mocked_post:
            d = {
                "result": {
                    "accountID": "12346536",
                    "userType": "1",
                    "token": "somevaluehere"
                },
                "code": 0
            }
            mocked_post.return_value = (d, 200)

            data = self.vesync_1.login()
            body = Helpers.req_body(self.vesync_1, 'login')
            body['email'] = self.vesync_1.username
            body['password'] = Helpers.hash_password(self.vesync_1.password)
            mocked_post.assert_called_with('/cloud/v1/user/login',
                                           'post',
                                           json=body)
            self.assertTrue(data)
Ejemplo n.º 5
0
    def get_devices(self) -> tuple:
        """Return tuple listing outlets, switches, and fans of devices"""
        outlets = []
        switches = []
        fans = []
        bulbs = []
        if not self.enabled:
            return None

        self.in_process = True

        response, _ = helpers.call_api('/cloud/v1/deviceManaged/devices',
                                       'post',
                                       headers=helpers.req_headers(self),
                                       json=helpers.req_body(
                                           self, 'devicelist'))

        if response and helpers.check_response(response, 'get_devices'):
            if 'result' in response and 'list' in response['result']:
                device_list = response['result']['list']
                outlets, switches, fans, bulbs = self.process_devices(
                    device_list)
            else:
                logger.error('Device list in response not found')
        else:
            logger.warning('Error retrieving device list')

        self.in_process = False

        return (outlets, switches, fans, bulbs)
Ejemplo n.º 6
0
 def test_airpur_onoff(self, caplog, api_mock):
     """Test Air Purifier Device On/Off Methods."""
     self.mock_api.return_value = ({'code': 0}, 200)
     fan = VeSyncAir131(DEV_LIST_DETAIL, self.vesync_obj)
     head = helpers.req_headers(self.vesync_obj)
     body = helpers.req_body(self.vesync_obj, 'devicestatus')
     fan.device_status = 'off'
     body['status'] = 'on'
     body['uuid'] = fan.uuid
     on = fan.turn_on()
     self.mock_api.assert_called_with(
         '/131airPurifier/v1/device/deviceStatus',
         'put',
         json_object=body,
         headers=head)
     call_args = self.mock_api.call_args_list[0][0]
     assert call_args[0] == '/131airPurifier/v1/device/deviceStatus'
     assert call_args[1] == 'put'
     assert on
     fan.device_status = 'on'
     off = fan.turn_off()
     body['status'] = 'off'
     self.mock_api.assert_called_with(
         '/131airPurifier/v1/device/deviceStatus',
         'put',
         json_object=body,
         headers=head)
     assert off
Ejemplo n.º 7
0
    def get_details(self) -> None:
        """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_object=body,
        )

        attr_list = (
            'deviceStatus',
            'activeTime',
            'energy',
            'power',
            'voltage',
            'nightLightStatus',
            'nightLightAutomode',
            'nightLightBrightness',
        )

        if Helpers.code_check(r) and all(k in r for k in attr_list):

            self.device_status = r.get('deviceStatus')
            self.connection_status = r.get('connectionStatus')
            self.nightlight_status = r.get('nightLightStatus')
            self.nightlight_brightness = r.get('nightLightBrightness')
            self.details = Helpers.build_details_dict(r)
        else:
            logger.debug('Unable to get %s details', self.device_name)
Ejemplo n.º 8
0
    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 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
Ejemplo n.º 9
0
    def set_brightness(self, brightness: int) -> bool:
        """Set brightness of tunable bulb."""
        if not self.dimmable_feature:
            logger.debug('%s is not dimmable', self.device_name)
            return False
        if brightness <= 0 or brightness > 100:
            logger.debug('Invalid brightness')
            return False

        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.code_check(r):
            self._brightness = brightness
            return True
        else:
            self.device_status = 'off'
            self.connection_status = 'offline'
            logger.debug('%s offline', self.device_name)

        logger.debug('Error setting brightness for %s', self.device_name)
        return False
Ejemplo n.º 10
0
    def get_devices(self) -> bool:
        """Return tuple listing outlets, switches, and fans of devices."""
        if not self.enabled:
            return False

        self.in_process = True
        proc_return = False
        response, _ = Helpers.call_api(
            '/cloud/v1/deviceManaged/devices',
            'post',
            headers=Helpers.req_header_bypass(),
            json_object=Helpers.req_body(self, 'devicelist'),
        )

        if response and Helpers.code_check(response):
            if 'result' in response and 'list' in response['result']:
                device_list = response['result']['list']
                proc_return = self.process_devices(device_list)
            else:
                logger.error('Device list in response not found')
        else:
            logger.warning('Error retrieving device list')

        self.in_process = False

        return proc_return
Ejemplo n.º 11
0
    def login(self) -> bool:
        """Return True if log in request succeeds."""
        user_check = isinstance(self.username, str) and len(self.username) > 0
        pass_check = isinstance(self.password, str) and len(self.password) > 0
        if user_check is False:
            logger.error('Username invalid')
            return False
        if pass_check is False:
            logger.error('Password invalid')
            return False

        response, _ = Helpers.call_api('/cloud/v1/user/login',
                                       'post',
                                       json_object=Helpers.req_body(
                                           self, 'login'))

        if Helpers.code_check(response) and 'result' in response:
            self.token = response.get('result').get('token')
            self.account_id = response.get('result').get('accountID')
            self.enabled = True
            logger.debug('Login successful')
            logger.debug('token %s', self.token)
            logger.debug('account_id %s', self.account_id)

            return True
        logger.error('Error logging in with username and password')
        return False
Ejemplo n.º 12
0
    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.code_check(r):
            self._rgb_status = status
            if body.get('rgbValue') is not None:
                self._rgb_value = {'red': red, 'blue': blue, 'green': green}
            return True
        logger.warning('Error turning %s off', self.device_name)
        return False
Ejemplo n.º 13
0
    def test_outdoor_outlet_onoff(self, caplog, api_mock):
        """Test Outdoor Outlet Device On/Off Methods"""
        self.mock_api.return_value = ({"code": 0}, 200)
        outdoor_outlet = VeSyncOutdoorPlug(DEV_LIST_DETAIL, self.vesync_obj)
        head = helpers.req_headers(self.vesync_obj)
        body = helpers.req_body(self.vesync_obj, 'devicestatus')

        body['status'] = 'on'
        body['uuid'] = outdoor_outlet.uuid
        body['switchNo'] = outdoor_outlet.sub_device_no
        on = outdoor_outlet.turn_on()
        self.mock_api.assert_called_with(
            '/outdoorsocket15a/v1/device/devicestatus',
            'put',
            headers=head,
            json=body)
        assert on
        off = outdoor_outlet.turn_off()
        body['status'] = 'off'
        self.mock_api.assert_called_with(
            '/outdoorsocket15a/v1/device/devicestatus',
            'put',
            headers=head,
            json=body)
        assert off
Ejemplo n.º 14
0
 def toggle(self, status) -> bool:
     """Toggle multicolor bulb."""
     body = helpers.req_body(self.manager, 'bypassV2')
     if status == 'off':
         status_bool = False
     else:
         status_bool = True
     body['cid'] = self.cid
     body['configModule'] = self.config_module
     body['payload'] = {
         'method': 'setSwitch',
         'source': 'APP',
         'data': {
             'id': 0,
             'enabled': status_bool,
         }
     }
     r, _ = helpers.call_api('/cloud/v2/deviceManaged/bypassV2',
                             'post',
                             headers=helpers.req_header_bypass(),
                             json_object=body)
     if helpers.code_check(r):
         self.device_status = status
         return True
     logger.debug('%s offline', self.device_name)
     self.device_status = 'off'
     self.connection_status = 'offline'
     return False
Ejemplo n.º 15
0
    def get_details(self):
        """Build details dictionary."""
        body = helpers.req_body(self.manager, 'devicedetail')
        body['pageSize'] = 100
        body['page'] = 1
        body['debugMode'] = False
        body['allData'] = True
        body['method'] = 'getWeighingDataV2'
        body['configModule'] = self.config_module
        head = helpers.req_headers(self.manager)

        r, _ = helpers.call_api(
            '/cloud/v2/deviceManaged/getWeighingDataV2',
            method='post',
            headers=head,
            json=body
        )
        subuser_dict = {}
        if r is not None and helpers.code_check(r):
            if not isinstance(r.get('result', {}).get('weightDatas'), list):
                logger.warning("Error in getting %s weight data", self.device_name)
                return
            subuser_dict = self.bt_data_builder(r.get('result').get('weightDatas'))

        self.details = subuser_dict
Ejemplo n.º 16
0
    def set_brightness(self, brightness: int):
        """Set brightness of vesync 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('{} is not dimmable - ', self.device_name)
Ejemplo n.º 17
0
    def set_brightness(self, brightness: int):
        """Set brightness of dimmable bulb."""
        if not self.dimmable_feature:
            logger.debug('%s is not dimmable', self.device_name)
            return False
        if isinstance(brightness, int) and (brightness <= 0
                                            or brightness > 100):
            logger.warning('Invalid brightness')
            return False

        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.code_check(r):
            self._brightness = brightness
            return True

        logger.debug('Error setting brightness for %s', self.device_name)
        return False
Ejemplo n.º 18
0
 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 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'))
Ejemplo n.º 19
0
    def test_login(self):
        """Test login method."""
        mock_vesync = mock.Mock()
        mock_vesync.login.return_value = True
        self.assertTrue(mock_vesync.login())
        mock_vesync.login.return_value = False
        self.assertFalse(mock_vesync.login())

        with patch('pyvesync.helpers.Helpers.call_api') as mocked_post:
            d = {
                'result': {
                    'accountID': '12346536',
                    'userType': '1',
                    'token': 'somevaluehere',
                },
                'code': 0,
            }
            mocked_post.return_value = (d, 200)

            data = self.vesync_1.login()
            body = Helpers.req_body(self.vesync_1, 'login')
            body['email'] = self.vesync_1.username
            body['password'] = Helpers.hash_password(self.vesync_1.password)
            mocked_post.assert_called_with('/cloud/v1/user/login',
                                           'post',
                                           json_object=body)
            self.assertTrue(data)
Ejemplo n.º 20
0
    def set_brightness(self, brightness: int) -> bool:
        """Set brightness of dimmable bulb."""
        if not self.dimmable_feature:
            logger.debug('%s is not dimmable', self.device_name)
            return False
        if not isinstance(brightness, int):
            logger.error('Error: brightness value should be a integer '
                         'number between 1 and 100')
            return False
        if brightness < 1 or brightness > 100:
            logger.warning('Warning: brightness value should be '
                           'between 1 and 100')
        # ensure brightness is between 0 and 100
        brightness = max(1, (min(100, brightness)))

        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_object=body,
        )

        if helpers.code_check(r):
            self._brightness = brightness
            return True

        logger.debug('Error setting brightness for %s', self.device_name)
        return False
Ejemplo n.º 21
0
    def change_fan_speed(self, speed: int = None) -> bool:
        """1,2,3,4 or call without argument to increment by 1."""
        if self.mode != 'manual':
            logger.debug('%s not in manual mode, cannot change speed',
                         self.device_name)
            return False

        try:
            level = int(self.speed)
        except KeyError:
            logger.debug(
                'Cannot change fan speed, no level set for %s',
                self.device_name,
            )
            return False

        body = Helpers.req_body(self.manager, 'devicestatus')
        body['uuid'] = self.uuid
        head = Helpers.req_headers(self.manager)
        if speed is not None:
            if speed == level:
                return True
            if speed in [1, 2, 3, 4]:
                level = speed
            else:
                logger.debug('Invalid fan speed for %s', self.device_name)
                return False
        else:
            if (level + 1) > 4:
                level = 1
            else:
                level = int(level + 1)

        head, body = self.__build_api_dict('setLevel')
        if not head and not body:
            return False

        body['payload']['data'] = {
            'id': 0,
            'level': level,
            'type': 'wind',
        }

        r, _ = Helpers.call_api(
            '/cloud/v2/deviceManaged/bypassV2',
            method='post',
            headers=head,
            json=body,
        )

        if r is not None and Helpers.code_check(r):
            self.speed = level
            return True
        logger.warning('Error changing %s speed', self.device_name)
        return False
Ejemplo n.º 22
0
    def get_config(self):
        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)
Ejemplo n.º 23
0
    def test_bad_login(self, api_mock, email, password, testid):

        full_return = ({'code': 455}, 200)
        self.mock_api.return_value = full_return
        vesync_obj = VeSync(email, password)
        assert vesync_obj.login() is False
        if testid == 'correct':
            jd = helpers.req_body(vesync_obj, 'login')
            self.mock_api.assert_called_with('/cloud/v1/user/login',
                                             'post',
                                             json=jd)
        else:
            assert not self.mock_api.called
Ejemplo n.º 24
0
 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.code_check(r):
         self.device_status = status
         return True
     return False
Ejemplo n.º 25
0
    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')
Ejemplo n.º 26
0
 def toggle(self, status):
     """Toggle vesync 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
Ejemplo n.º 27
0
    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.code_check(r):
            self.config = helpers.build_config_dict(r)
        else:
            logger.debug("Error getting %s config info", self.device_name)
Ejemplo n.º 28
0
 def get_details(self):
     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))
Ejemplo n.º 29
0
    def change_fan_speed(self, speed: int = None) -> bool:
        """Adjust Fan Speed by Specifying 1,2,3 as argument or cycle
            through speeds increasing by one"""
        if self.mode != 'manual':
            logger.debug(
                '{} not in manual mode, cannot change speed'.format(
                    self.device_name))
            return False

        try:
            level = self.details['level']
        except KeyError:
            logger.debug(
                'Cannot change fan speed, no level set for {}'.format(
                    self.device_name))
            return False

        body = helpers.req_body(self.manager, 'devicestatus')
        body['uuid'] = self.uuid
        head = helpers.req_headers(self.manager)
        if speed is not None:
            if speed == level:
                return True
            elif speed in [1, 2, 3]:
                body['level'] = speed
            else:
                logger.debug(
                    'Invalid fan speed for {}'.format(self.device_name))
                return False
        else:
            if (level + 1) > 3:
                body['level'] = 1
            else:
                body['level'] = int(level + 1)

        r, _ = helpers.call_api(
            '/131airPurifier/v1/device/updateSpeed',
            'put',
            json=body,
            headers=head
        )

        if r is not None and helpers.check_response(r, 'airpur_status'):
            self.details['level'] = body['level']
            return True
        else:
            logger.warning(
                'Error changing {} speed'.format(self.device_name))
            return False
Ejemplo n.º 30
0
    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.code_check(response):
            self.energy['year'] = helpers.build_energy_dict(response)
        else:
            logger.debug('Unable to get %s yearly data', self.device_name)