コード例 #1
0
# Copyright (c) 2015-2018 Digi International Inc. All rights reserved.
#
# This code is originally from another Digi Open Source Library:
# https://github.com/digidotcom/idigi-python-monitor-api

import xml.etree.ElementTree as ET
import logging
import textwrap
from devicecloud.apibase import APIBase
from devicecloud.conditions import Attribute
from devicecloud.monitor_tcp import TCPClientManager

logger = logging.getLogger(__name__)

#: System-generated identifier for the monitor.
MON_ID_ATTR = Attribute("monId")

#: Device Cloud customer identifier.
MON_CST_ID_ATTR = Attribute("cstId")

#: One or more topics to monitor separated by comma.  See Device Cloud
#: documentation for more details
MON_TOPIC_ATTR = Attribute("monTopic")

#: Format for delivered event data: xml, json
MON_FORMAT_TYPE_ATTR = Attribute("monFormatType")

#: Transport method used to deliver push notifications to the
#: client application: tcp, http
MON_TRANSPORT_TYPE_ATTR = Attribute("monTransportType")
コード例 #2
0
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (c) 2014 Etherios, Inc. All rights reserved.
# Etherios, Inc. is a Division of Digi International.

"""Provide access to the device cloud filedata API"""

import base64

from devicecloud.apibase import APIBase
from devicecloud.conditions import Attribute, Expression
from devicecloud.util import iso8601_to_dt, validate_type
import six


fd_path = Attribute("fdPath")
fd_name = Attribute("fdName")
fd_type = Attribute("fdType")
fd_customer_id = Attribute("customer_id")
fd_created_date = Attribute("fdCreatedDate")
fd_last_modified_date = Attribute("fdLastModifiedDate")
fd_content_type = Attribute("fdContentType")
fd_size = Attribute("fdSize")


class FileDataAPI(APIBase):
    """Encapsulate data and logic required to interact with the device cloud file data store"""

    def get_filedata(self, condition=None, page_size=1000):
        """Return a generator over all results matching the provided condition
コード例 #3
0
 def test_multi_combination(self):
     a = Attribute("a")
     self.assertEqual(((a > 1) & (a > 2) & (a > 3)).compile(),
                      "a>'1' and a>'2' and a>'3'")
コード例 #4
0
 def test_gt(self):
     a = Attribute("a")
     self.assertEqual((a > 21).compile(), "a>'21'")
コード例 #5
0
 def test_or(self):
     a = Attribute("a")
     b = Attribute("b")
     expr = (a.like("%.csv")) | (b < 1024)
     self.assertEqual(expr.compile(), "a like '%.csv' or b<'1024'")
コード例 #6
0
 def test_datacmp(self):
     a = Attribute("a")
     self.assertEqual((a < datetime.datetime(2014, 7, 7)).compile(),
                      "a<'2014-07-07T00:00:00Z'")
コード例 #7
0
 def test_and(self):
     a = Attribute("a")
     b = Attribute("b")
     expr = (a > 21) & (b == "Amsterdam")
     self.assertEqual(expr.compile(), "a>'21' and b='Amsterdam'")
コード例 #8
0
 def test_like(self):
     a = Attribute("a")
     self.assertEqual(a.like(r"%.txt").compile(), "a like '%.txt'")
コード例 #9
0
 def test_eq(self):
     a = Attribute("a")
     self.assertEqual((a == "a string").compile(), "a='a string'")
コード例 #10
0
 def test_lt(self):
     a = Attribute("a")
     self.assertEqual((a < 25).compile(), "a<'25'")
コード例 #11
0
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (c) 2015 Digi International, Inc.
import sys
import xml.etree.ElementTree as ET

from devicecloud.apibase import APIBase
from devicecloud.conditions import Attribute, Expression
from devicecloud.util import iso8601_to_dt, validate_type
import six

dev_mac = Attribute('devMac')
group_id = Attribute('grpId')
group_path = Attribute('grpPath')
dev_connectware_id = Attribute('devConnectwareId')
# TODO: Can we support location based device lookups? (e.g. lat/long?)


ADD_GROUP_TEMPLATE = \
"""
<DeviceCore>
    <devConnectwareId>{connectware_id}</devConnectwareId>
    <grpPath>{group_path}</grpPath>
</DeviceCore>
"""


class DeviceCoreAPI(APIBase):
    """Encapsulate DeviceCore interface"""