'Get the latest data from the Fitbit API and update the states.'

def update(self):

    if ((self.resource_type == 'devices/battery') and self.extra):
        self._state = self.extra.get('battery')
    else:
        container = self.resource_type.replace('/', '-')
        response = self.client.time_series(self.resource_type, period='7d')
        self._state = response[container][(-1)].get('value')
    if (self.resource_type == 'activities/heart'):
        self._state = response[container][(-1)].get('value').get('restingHeartRate')
    config_contents = {ATTR_ACCESS_TOKEN: self.client.client.token['access_token'], ATTR_REFRESH_TOKEN: self.client.client.token['refresh_token'], ATTR_CLIENT_ID: self.client.client.client_id, ATTR_CLIENT_SECRET: self.client.client.client_secret, ATTR_LAST_SAVED_AT: int(time.time())}
    if (not config_from_file(self.config_path, config_contents)):
        _LOGGER.error('Failed    to    save    config    file')
