コード例 #1
0
    def create_value(self, label, vtype=None, lang=None, description=None, unit=None, data=None):
        """
        If vtype is not specified then the value (lang, description & unit are ignored)
        data can be specified on it's own
        """
        label = Validation.label_check_convert(label)
        if vtype is not None:
            vtype = Validation.value_type_check_convert(vtype)
            lang = Validation.lang_check_convert(lang, allow_none=True)
            description = Validation.comment_check_convert(description, allow_none=True)
            unit = unit
        if vtype is None and data is None:
            raise AttributeError("create_value with no vtype and no data!")
        with self.lock:
            try:
                value = self.__values[label]
            except KeyError:
                value = self.__values[label] = {}

            if vtype is not None:
                new_value = {VTYPE: vtype,
                             LANG: lang,
                             DESCRIPTION: description,
                             UNIT: unit}
                if new_value != value:
                    value.update(new_value)
                    if VALUE + label not in self._changes:
                        logger.debug('Value %s has changed', label)
                        self._changes.append(VALUE + label)

            if data is not None:
                value[SHAREDATA] = data
                if VALUESHARE + label not in self._changes:
                    logger.debug('Sharing value data for %s', label)
                    self._changes.append(VALUESHARE + label)
コード例 #2
0
ファイル: Point.py プロジェクト: whaleygeek/py-IoticAgent
 def __init__(self, client, foc, lid, pid, guid):
     self.__client = client
     Validation.foc_check(foc)
     self.__foc = foc
     self.__lid = Validation.lid_check_convert(lid)
     self.__pid = Validation.pid_check_convert(pid)
     self.__guid = Validation.guid_check_convert(guid)
コード例 #3
0
ファイル: Thing.py プロジェクト: aniknarayan/ioticiser_new
 def set_location(self, lat, long):  # pylint: disable=redefined-builtin
     with self.lock:
         Validation.location_check(lat, long)
         if self.__lat != lat or self.__long != long:
             if LOCATION not in self._changes:
                 self._changes.append(LOCATION)
             self.__lat = lat
             self.__long = long
コード例 #4
0
ファイル: Thing.py プロジェクト: aniknarayan/ioticiser_new
 def __init__(self, client, lid, guid, epId):
     super(Thing, self).__init__(client, guid)
     self.__lid = Validation.lid_check_convert(lid)
     self.__epId = Validation.guid_check_convert(epId, allow_none=True)
     # Keep track of newly created points & subs (the requests for which originated from current agent)
     self.__new_feeds = ThreadSafeDict()
     self.__new_controls = ThreadSafeDict()
     self.__new_subs = ThreadSafeDict()
コード例 #5
0
ファイル: Thing.py プロジェクト: whaleygeek/py-IoticAgent
 def __init__(self, client, lid, guid, epId):
     self.__client = client
     self.__lid = Validation.lid_check_convert(lid)
     self.__guid = Validation.guid_check_convert(guid)
     self.__epId = Validation.guid_check_convert(epId)
     #
     # Keep track of newly created points & subs (the requests for which originated from current agent)
     self.__new_feeds = ThreadSafeDict()
     self.__new_controls = ThreadSafeDict()
     self.__new_subs = ThreadSafeDict()
コード例 #6
0
    def get_recent_async(self, count, callback):
        """
        Similar to `get_recent` except instead of returning an iterable, passes each dict to the given function which
        must accept a single argument.

        Returns:
            The request.

        Args:
            callback (function): instead of returning an iterable, pass each dict (as described above) to the given
                function which must accept a single argument. Nothing is returned.
        """
        validate_nonnegative_int(count, 'count')
        Validation.callable_check(callback, allow_none=True)
        evt = self._client._request_sub_recent(self.subid, count=count)
        self._client._add_recent_cb_for(evt, callback)
        return evt
コード例 #7
0
ファイル: Thing.py プロジェクト: aniknarayan/ioticiser_new
 def set_public(self, public=True):
     with self.lock:
         res = Validation.bool_check_convert('public', public)
         if res != self.__public and PUBLIC not in self._changes:
             logger.debug('adding public %s -> %s', repr(self.__public),
                          repr(res))
             self._changes.append(PUBLIC)
         self.__public = res
コード例 #8
0
ファイル: Thing.py プロジェクト: aniknarayan/ioticiser_new
 def __init__(self,
              lid,
              new=False,
              stash=None,
              public=None,
              labels=None,
              descriptions=None,
              tags=None,
              points=None,
              lat=None,
              long=None):  # pylint: disable=redefined-builtin
     """
     # Note labels & descriptions: dict like {'en': 'blah', 'fr': 'chips'}
     # Note points dict = stash format
     """
     super(Thing, self).__init__(lid,
                                 new=new,
                                 labels=labels,
                                 descriptions=descriptions,
                                 tags=tags)
     self.__stash = stash
     self.__public = Validation.bool_check_convert(
         'public', public)  # Note: bool(None) == False
     self.__lat = None
     self.__long = None
     if lat is not None or long is not None:
         Validation.location_check(lat, long)
         self.__lat = lat
         self.__long = long
     self.__points = {}
     if points is not None:
         for pid, pdata in points.items():
             point_tags = [
             ]  # Migrate stash where point[tags] was not stored in empty case
             if TAGS in pdata:
                 point_tags = pdata[TAGS]
             self.__points[pid] = Point(pdata[FOC],
                                        pid,
                                        labels=pdata[LABELS],
                                        descriptions=pdata[DESCRIPTIONS],
                                        tags=point_tags,
                                        values=pdata[VALUES],
                                        max_samples=pdata[RECENT])
コード例 #9
0
 def share(self, data=None, time=None):
     if data is None and time is None:
         raise ValueError("kwarg data or time required.")
     with self.lock:
         if time is not None:
             self.__sharetime = Validation.datetime_check_convert(time, allow_none=True)
             if SHARETIME not in self._changes:
                 self._changes.append(SHARETIME)
         if data is not None:
             self.__sharedata = data
             if SHAREDATA not in self._changes:
                 self._changes.append(SHAREDATA)
コード例 #10
0
    def __init__(self, point, client):
        """point - instance of Point, RemoteFeed or RemoteControl or a valid GUID
           client - instance of IOT.Client
        """
        # remote => use describe, non-remote => use point value listing
        if isinstance(point, Point):
            self.__remote = False
            self.__point = point
        elif isinstance(point, (RemoteFeed, RemoteControl)):
            self.__point = point.guid
            self.__remote = True
        else:
            self.__point = Validation.guid_check_convert(point)
            self.__remote = True

        self.__lock = Lock()
        self.__client = client
        # flag to prevent repeated fetching of value metadata
        self.__last_parse_ok = True
        self.__value_templates = None
        self.__filter = None
コード例 #11
0
    def __init__(self, point, client):
        """point - instance of Point, RemoteFeed or RemoteControl or a valid GUID
           client - instance of IOT.Client
        """
        # remote => use describe, non-remote => use point value listing
        if isinstance(point, Point):
            self.__remote = False
            self.__point = point
        elif isinstance(point, RemotePoint):
            self.__point = point.guid
            self.__remote = True
        else:
            self.__point = Validation.guid_check_convert(point)
            self.__remote = True

        self.__lock = Lock()
        self.__client = client
        # flag to prevent repeated fetching of value metadata
        self.__last_parse_ok = True
        self.__value_templates = None
        self.__filter = None
コード例 #12
0
ファイル: Thing.py プロジェクト: Iotic-Labs/py-IoticAgent
 def __get_parsed_control_callback(self, pid, callback, callback_parsed):
     Validation.callable_check(callback_parsed)
     return partial(self.__client._parsed_callback_wrapper, callback_parsed, callback, R_CONTROL,
                    # used by PointDataObjectHandler as reference
                    Point(self.__client, R_CONTROL, self.__lid, pid, '0'*32))
コード例 #13
0
 def __init__(self, client, subid, feedid, lid):
     self.__client = client
     self.__subid = Validation.guid_check_convert(subid)
     self.__feedid = Validation.guid_check_convert(feedid)
     self.__lid = Validation.lid_check_convert(lid)
コード例 #14
0
ファイル: Resource.py プロジェクト: aniknarayan/ioticiser_new
 def __init__(self, client, guid):
     self.__client = client
     self.__guid = Validation.guid_check_convert(guid)
コード例 #15
0
 def __init__(self, client, subid, pointid, lid):
     self.__client = client
     self.__subid = Validation.guid_check_convert(subid)
     self.__pointid = Validation.guid_check_convert(pointid)
     self.__lid = Validation.lid_check_convert(lid)
コード例 #16
0
 def __init__(self, client, subid, controlid):
     self.__client = client
     self.__subid = Validation.guid_check_convert(subid)
     self.__controlid = Validation.guid_check_convert(controlid)
コード例 #17
0
ファイル: Client.py プロジェクト: Iotic-Labs/py-IoticAgent
 def _get_parsed_feed_callback(self, callback_parsed, callback):
     Validation.callable_check(callback_parsed)
     return partial(self._parsed_callback_wrapper, callback_parsed, callback, R_FEED, None)