Exemplo n.º 1
0
def fetch_data(master_dict):
    """
    loops through the master device list and pulls the corresponding data from the BAS system

    :param master_dict: the master dict created in load_master_dict
    :return: master_dict
    """
    http = urllib3.PoolManager()
    for device in master_dict.values():
        try:
            print("GET request to ", device.ip_address)
            r = http.request('GET',
                             device.ip_address,
                             timeout=urllib3.Timeout(connect=10.0))

            # if device.ip_address in '10.1.13.71/pe/vav2.15.xml':
            #     print("Max")

            master_dict = process_xml(master_dict,
                                      xml_as_obj=r.data.decode("utf-8"),
                                      tag=device.name)
        except Exception as e:
            # catching all exceptions. Should not be the case
            print(e)
            logging.warning(e)
            continue
    return master_dict
Exemplo n.º 2
0
 def _simple_point_write(self, pointlist, num):
     results = []
     for point_dict in pointlist:
         print("writing ", point_dict['id'])
         res = self.session.his_write(point_dict['id'],
                                      {point_dict['ts']: point_dict['val']})
         if res.is_failed:
             try:
                 logging.warning(point_dict['id'], 'failed ', res.result)
             except pyhaystack.exception.HaystackError as e:
                 logging.warning(e)
         else:
             print("completed ", point_dict['id'])
         results.append(res)
     return num, results
Exemplo n.º 3
0
 def _data_type_handler(self, value):
     new_value = None
     if self._point.tags['kind'] == 'Bool':
         try:
             on_off = value.lower() in ['on', 'off']
             if on_off:
                 new_value = True if value.lower() == 'on' else False
             else:
                 value = int(value)
                 new_value = value > 0
         except AttributeError:
             if value:
                 new_value = value > 0
     elif self._point.tags['kind'] == 'Number':
         try:
             new_value = float(value)
         except (TypeError, ValueError):
             new_value = 0
             logging.warning(
                 f"{self._point.id} has a data type mismatch. "
                 f"Kind is {self._point.tags['kind']}, value is {value}")
     return new_value if new_value is not None else value
Exemplo n.º 4
0
    def write_point_val(self, equip_name, point_name, time, value):
        """
        The master function in the SkySpark class. It writes the value to the specified measurement point

        :param equip_name: The name of the equipment
        :param point_name: The name of the measurement point
        :param time: The time of the value being written
        :param value: The value to write
        :return: None
        """
        # only fetch the equipment if it is different than the last point write. To save time
        self._check_equip(equip_name)
        try:
            self._set_point(point_name)
            res = self._write_point(time, value)
            if res.is_failed:
                logging.warning('Error writing point: ', equip_name,
                                point_name)
            return res
        except AttributeError:
            print('Point wasnt written: ', equip_name, point_name)
            return 0.
Exemplo n.º 5
0
    def _set_point(self, point_name):
        """
        Fetching the point (measurement) object.

        :param point_name: the name of the measurement point. Needs to be exact
        :return: a measurement object
        """
        point_list = list(
            self._equip.find_entity(
                fb.Field('navName') == fb.Scalar(point_name)).result.values())
        # if more than 1 point is returned with the given name, there is an issue. point names must be unique
        if len(point_list) > 1:
            logging.warning(
                "More than one value was returned for a point name of ",
                point_name)

        # catches if the point doesn't exist on the point
        elif len(point_list) < 1:
            logging.warning("the point name doesn't exist on the equipment %s",
                            point_name)
            raise AttributeError
        self._point = point_list[0]