Esempio n. 1
0
 def __init__(self):
     """Initialises the Client token and obtains the raw_data
         of the devices
     """
     lifx_cred = Setting("lifx")
     self.getclienttoken = lifx_cred.setting["client_auth"]["_CLIENT_TOKEN"]
     self.rawData = self.get_request(lifx_cred.get("url")["_DEVICELIST_REQ"])
Esempio n. 2
0
    def __init__(self):
        """
        Initialises the Client Id and Client key and obtains the Access
        token of the netatmo device

        Args as Data:
                clientid: #netatmo id of the user
                clientsecret: #netatmo secret key of the user
                username: #username used in netatmo login
                password: #password used in netatmo login
        """
        netatmo_cred = Setting("netatmo")
        self.clientId = netatmo_cred.setting['client_auth']['_CLIENT_ID']
        self.clientSecret = netatmo_cred.setting['client_auth'][
            '_CLIENT_SECRET']
        self.username = netatmo_cred.setting['client_auth']['_USERNAME']
        self.password = netatmo_cred.setting['client_auth']['_PASSWORD']
        postparams = {
            "grant_type": "password",
            "client_id": self.clientId,
            "client_secret": self.clientSecret,
            "username": self.username,
            "password": self.password,
            "scope": "read_station"
        }
        self._AUTH_REQ = netatmo_cred.get("url")["_AUTH_REQ"]
        response = get_request(self._AUTH_REQ, postparams)
        self._clientId = self.clientId
        self._clientSecret = self.clientSecret
        self._accessToken = response['access_token']
        self.refreshToken = response['refresh_token']
        self._scope = response['scope']
        self.expiration = int(response['expire_in'] + time.time())
Esempio n. 3
0
    def __init__(self):
        """
            Initialize using zwave.json config file defined in CONFIG variable
        """
        # check will not be changed once it is initialized
        global listen
        global MAX_THREAD
        multisensor_cred = Setting(CONFIG)
        self.device = str(multisensor_cred.setting["device"])
        self.log = str(multisensor_cred.setting["log"])
        self.log_file = str(multisensor_cred.setting["log_file"])
        self.write_file = bool(multisensor_cred.setting["write_log_file"])
        self.output_console = bool(multisensor_cred.setting["write_console"])

        self.config = {}
        # format config dict
        for config_k, config_v in multisensor_cred.setting["config"].items():
            item = {}
            for k, v in config_v.iteritems():
                item[int(k)] = int(v)
            self.config[int(config_k)] = item
        # format listen item
        for k, v in multisensor_cred.setting["listen"].items():
            item = []
            for node in v:
                item.append(str(node))
            listen[int(k)] = item
        MAX_THREAD = int(multisensor_cred.setting["MAX_THREAD"])
Esempio n. 4
0
    def setup(self):
        '''
        Obtains the access token if present and calls the access_token()
        function if the access_token is not present, using the Product Id,
        Product Secret, and PIN.

        Args as Data:
                Product_id: #product id of the registered product
                Product_secret: #product secret of the registered product
                PIN: #generated by clicking on the authorization url,
                      must be updated after every use
                access_token: #needed for access. If it is not present, the
                              other three args are used to generate it.
        '''
        credentials = Setting(self.credentials_file)
        self.urls = credentials.setting["url"]
        self._accessToken = credentials.setting["credentials"]["access_token"]
                                                # get the access token

        if (self._accessToken == ""):
        # generate access token if it is not present
            self.code, self.client_id, self.client_secret = (
                        credentials.setting["credentials"]["PIN"],
                        credentials.setting["credentials"]["Product_id"],
                        credentials.setting["credentials"]["Product_secret"])
            self.access_token()
        self.devices = dict() # generate an empty dictionary for all NEST
Esempio n. 5
0
 def __init__(self):
     mother_cred = Setting("mother")
     self.username = mother_cred.setting['client_auth']['_USERNAME']
     self.password = mother_cred.setting['client_auth']['_PASSWORD']
     self.mac_id = mother_cred.setting['mac_id']
     params = {
         'username': str(self.username),
         'password': str(self.password)
     }
     self._AUTH_REQ = mother_cred.get("url")["_AUTH_REQ"]
     self._NODE_REQ = mother_cred.get("url")["_NODE_REQ"]
     response = requests.post(self._AUTH_REQ, params).json()
     if 'token' in response:
         self.api_token = response["token"]
     else:
         print self.api_token, "Error"
         exit(1)
Esempio n. 6
0
 def __init__(self, data):
     """Initialises the sensor data and client data of the sensors"""
     bdcredentials = Setting("bd_setting")
     self.data = bdcredentials.setting
     self.sensor_data = json.loads(data)['sensor_data']
     self.data["mac_id"] = self.sensor_data["mac_id"]
     self.sensor_data.pop("mac_id")
     self.url = bdcredentials.setting["url"]
     self.metadata = []
     self.common_data = []
Esempio n. 7
0
 def __init__(self):
     """
         Initialize using zwave.json config file defined in CONFIG variable
     """
     multisensor_cred = Setting(CONFIG)
     self.device = str(multisensor_cred.setting["device"])
     self.log = str(multisensor_cred.setting["log"])
     self.log_file = str(multisensor_cred.setting["log_file"])
     self.write_file = bool(multisensor_cred.setting["write_log_file"])
     self.output_console = bool(multisensor_cred.setting["write_console"])
Esempio n. 8
0
    def __init__(self, network):
        """
            the zwave sensor is able to be launched in contextual of instance 
            of ZwaveNetwork

            Args: network the instance of ZwaveNetwork
            Return: None
        """
        multisensor_cred = Setting(CONFIG)
        self.network = network.network   # nethwork instance
Esempio n. 9
0
 def get_device_data(self):
     """Get the device data information uncomment any of these to make
                work if device is connected retrieve device information in the
                format"status=switch.energyinfo()"
             """
     wemo_cred = Setting("wemo")
     mac_id = wemo_cred.setting["mac_id"]
     edata = self.energy_info()
     data = {'sensor_data': {}}
     data['sensor_data'].update(edata)
     data['sensor_data'].update({"mac_id": mac_id})
Esempio n. 10
0
 def __init__(self, authdata):
     """
         Initilize the auth token and obtain the device modules data
         of Netatmo
         Args as data:
                         "authdata": class object of ClientAuth provides
                                     access token.
                                     
     """
     self.getAuthToken = authdata.access_token
     postparams = {
         "access_token": self.getAuthToken,
         "app_type": "app_station"
     }
     url_cred = Setting("netatmo")
     _DEVICELIST_REQ = url_cred.get("url")["_DEVICELIST_REQ"]
     response = get_request(_DEVICELIST_REQ, postparams)
     # print "\nDeviceList: ",resp
     self.rawData = response['body']
     self.stations = {d['_id']: d for d in self.rawData['devices']}
     # print  "\nStations: ",self.stations
     self.modules = {m['_id']: m for m in self.rawData['modules']}
     # print  "\nModules: ",self.modules
     self.default_station = list(self.stations.values())[0]['station_name']
Esempio n. 11
0
def socket_init():
    """
        Socket initialization

        Note: only the localhost process can be connected to this engine.

        Return: created socket
    """
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        host = socket.gethostname()
        port = int(Setting(CONFIG).setting["port"])
        s.connect((host, port))
        return s
    except Exception as e:
        sys.exit("Socket Creation Failed\n" + str(e))
import pytest
import time
from util.command import Command
from util.Base import Base
from config.setting import Setting  #文件路径类
from util.log import logger, insert_log
#https://coding.net/u/tsbc/p/PySelenium_PO
import sys

set = Setting()
cmd = Command()
log = logger("TestIndexWeb")


class TestIndexWeb(Base):  #大量用到所以用继承
    """
    pageobject 首个页面
    """
    flag = 3  #状态机
    base_url = "https://www.ctrip.com/"

    def setup_class(self):
        if not self.excel_close():
            log.info("Excel数据未关闭")
            raise Exception("Excel数据未关闭")
        try:
            self.driver = cmd.start_brower(self.base_url)
        except Exception as err:
            print(format(err))

    def teardown_class(self):
Esempio n. 13
0
 def __init__(self, identity):
     """Initialises the Client token and obtains the raw_data
         of the devices"""
     lifx_cred = Setting("lifx")
     self.getclienttoken = lifx_cred.setting["client_auth"]["_CLIENT_TOKEN"]
     self._DEVICE_REQ = lifx_cred.get("url")["_DEVICE_REQ"]
Esempio n. 14
0
 def __init__(self, identity):
     """Initialises the IP of the Wemo Switch"""
     wemo_cred = Setting("wemo")
     #self.ip = wemo_cred.setting["ip"]
     self.ip = identity
Esempio n. 15
0
 def __init__(self):
     setting = Setting()
     self.setting_dir_path = setting.setting_dir_path
Esempio n. 16
0
 def __init__(self):
     """Initialises the IP of the Wemo Switch"""
     wemo_cred = Setting("wemo")
     self.ip = wemo_cred.setting["ip"]