def __init__(self, clientId, clientSecret, username, password, verbose=True): self.clientId = clientId self.clientSecret = clientSecret self.username = username self.password = password self.smapee = smappy.Smappee(clientId, clientSecret) self.smapee.authenticate(username, password) self.service_location_id = self.smapee.get_service_locations( )['serviceLocations'][0]['serviceLocationId']
def __init__(self, client_id, client_secret, username, password): """Initialize the data.""" import smappy try: self._s = smappy.Smappee(client_id, client_secret) self._s.authenticate(username, password) except Exception as e: _LOGGER.error('Smappee authentication failed, %s', e) self.locations = {} self.info = {} self.update()
def main(): # Authenticate to Smappee s = smappy.Smappee(sys.argv[1], sys.argv[2]) s.authenticate(sys.argv[3], sys.argv[4]) # Retrieve appliances locs = s.get_service_locations() loc = locs['serviceLocations'][0] id = loc['serviceLocationId'] all = s.get_service_location_info(id) appliances = all['appliances'] # Write appliances to disk, in order to be processed by PHP dirpath = tempfile.gettempdir() with io.open(dirpath + '/Smappee.json', 'w', encoding='utf-8') as file: file.write(json.dumps(appliances, ensure_ascii=False)) print(len(appliances))
def main(): # Authenticate to Smappee s = smappy.Smappee(sys.argv[1], sys.argv[2]) s.authenticate(sys.argv[3], sys.argv[4]) # calculate time frame start = pandas.to_datetime('now').tz_localize( 'Europe/Paris') + pandas.Timedelta(minutes=-5) end = pandas.to_datetime('now').tz_localize('Europe/Paris') # Retrieve global electric consumption locs = s.get_service_locations() loc = locs['serviceLocations'][0] id = loc['serviceLocationId'] consumptions = s.get_consumption(id, start, end, 1) #print(consumptions) print(consumptions['consumptions'][0]['alwaysOn']) print(consumptions['consumptions'][0]['consumption'])
def __init__(self, client_id, client_secret, username, password, host, host_password): """Initialize the data.""" import smappy self._remote_active = False self._local_active = False if client_id is not None: try: self._smappy = smappy.Smappee(client_id, client_secret) self._smappy.authenticate(username, password) self._remote_active = True except RequestException as error: self._smappy = None _LOGGER.exception( "Smappee server authentication failed (%s)", error) else: _LOGGER.warning("Smappee server component init skipped.") if host is not None: try: self._localsmappy = smappy.LocalSmappee(host) self._localsmappy.logon(host_password) self._local_active = True except RequestException as error: self._localsmappy = None _LOGGER.exception( "Local Smappee device authentication failed (%s)", error) else: _LOGGER.warning("Smappee local component init skipped.") self.locations = {} self.info = {} self.consumption = {} self.sensor_consumption = {} self.instantaneous = {} if self._remote_active or self._local_active: self.update()
def init(): # Here we do the setup # Store access_token in OS X keychain on first run print('Enter your my.smappee.com username:'******'Enter your my.smappee.com password:'******'pvdabeel' client_secret = '' try: c = smappy.Smappee(client_id, client_secret) c.authenticate(init_username, init_password) init_password = '' init_access_token = c.access_token except HTTPError as e: print('Error contacting Smappee servers. Try again later.') print e time.sleep(0.5) return except URLError as e: print('Error: Unable to connect. Check your connection settings.') print e return except AttributeError as e: print( 'Error: Could not get an access token from Smappee. Try again later.' ) print e return except Exception as e: print('Error: Something went wrong:') print e return keyring.set_password("mysmappee-bitbar", "username", init_username) keyring.set_password("mysmappee-bitbar", "access_token", init_access_token)
def main(): # Authenticate to Smappee s = smappy.Smappee(sys.argv[1], sys.argv[2]) s.authenticate(sys.argv[3], sys.argv[4]) # calculate time frame start = pandas.to_datetime('now').tz_localize('UTC') + pandas.Timedelta(minutes=-5) end = pandas.to_datetime('now').tz_localize('UTC') # Retrieve global electric consumption locs = s.get_service_locations() loc = locs['serviceLocations'][0] id = loc['serviceLocationId'] #print(s.get_service_location_info(id)) consumption = s.get_events(service_location_id=id, start=start, end=end, max_number=1, appliance_id=sys.argv[5]) #print(consumption) if (len(consumption) > 0): print(consumption[0]['activePower']) print(consumption[0]['totalPower']) else: print(0) print(0)