diff --git a/docs/source/connect.rst b/docs/source/connect.rst index c5efd29..e0c16f0 100644 --- a/docs/source/connect.rst +++ b/docs/source/connect.rst @@ -93,7 +93,7 @@ arguments, so all should be usable. * ``grid_format``: This selects the grid serialisation format for the Project Haystack server. Some (e.g. nHaystack/Niagara AX) only support ZINC - serialisation, where as others (such as WideSky) work better with JSON. + serialisation, where as others (such as WideSky and Niagara4) work better with JSON. Most of the time, the default here will be selected appropriate for the underlying server implementation. Valid values are ``zinc`` and ``json``. diff --git a/pyhaystack/client/niagara.py b/pyhaystack/client/niagara.py index 3dc1a7d..0ea664b 100644 --- a/pyhaystack/client/niagara.py +++ b/pyhaystack/client/niagara.py @@ -76,17 +76,17 @@ class Niagara4HaystackSession(HaystackSession, BQLMixin, EncodingMixin): _AUTH_OPERATION = Niagara4ScramAuthenticateOperation _BQL_OPERATION = BQLOperation - def __init__(self, uri, username, password, **kwargs): + def __init__(self, uri, username, password, grid_format=hszinc.MODE_JSON, **kwargs): """ Initialise a Nagara 4 Project Haystack session handler. :param uri: Base URI for the Haystack installation. :param username: Authentication user name. :param password: Authentication password. + :param grid_format: the grid format to use in series (json, zinc) """ - super(Niagara4HaystackSession, self).__init__( - uri, "haystack", grid_format=hszinc.MODE_JSON, **kwargs + uri, "haystack", grid_format=grid_format, **kwargs ) self._username = username self._password = password diff --git a/pyhaystack/client/ops/grid.py b/pyhaystack/client/ops/grid.py index 15a9178..fb3beb3 100644 --- a/pyhaystack/client/ops/grid.py +++ b/pyhaystack/client/ops/grid.py @@ -24,7 +24,7 @@ class BaseAuthOperation(state.HaystackOperation): def __init__(self, session, uri, retries=2, cache=False): """ Initialise a request for the authenticating with the given URI and arguments. - + It also contains the state machine for reconnection if needed. :param session: Haystack HTTP session object. @@ -215,16 +215,15 @@ def __init__( cache_key = uri self._cache_key = cache_key - if not raw_response: - if expect_format == hszinc.MODE_ZINC: - self._headers[b"Accept"] = "text/zinc" - elif expect_format == hszinc.MODE_JSON: - self._headers[b"Accept"] = "application/json" - elif expect_format is not None: - raise ValueError( - "expect_format must be one onf hszinc.MODE_ZINC " - "or hszinc.MODE_JSON" - ) + if expect_format == hszinc.MODE_ZINC: + self._headers[b"Accept"] = "text/zinc" + elif expect_format == hszinc.MODE_JSON: + self._headers[b"Accept"] = "application/json" + elif expect_format is not None: + raise ValueError( + "expect_format must be one onf hszinc.MODE_ZINC " + "or hszinc.MODE_JSON" + ) def _do_check_cache(self, event): """ diff --git a/pyhaystack/client/ops/his.py b/pyhaystack/client/ops/his.py index c81e393..1f7f770 100644 --- a/pyhaystack/client/ops/his.py +++ b/pyhaystack/client/ops/his.py @@ -124,18 +124,28 @@ def _on_read(self, operation, **kwargs): # Convert grid to list of tuples data = [(conv_ts(row["ts"]), row["val"]) for row in grid] + units = "" + values = [] if self._series_format == self.FORMAT_DICT: data = dict(data) elif self._series_format == self.FORMAT_SERIES: # Split into index and data. try: (index, data) = zip(*data) - if isinstance(data[0], hszinc.Quantity): - values = [each.value for each in data] - units = data[0].unit + if isinstance(data[0], hszinc.Quantity) or isinstance( + data[-1], hszinc.Quantity + ): + for each in data: + try: + values.append(each.value) + if units == "": + units = each.unit + except AttributeError: + if isinstance(each, float): + values.append(each) + continue else: values = data - units = "" except ValueError: values = [] index = [] diff --git a/pyhaystack/info.py b/pyhaystack/info.py index 4f6cbc2..9da759e 100644 --- a/pyhaystack/info.py +++ b/pyhaystack/info.py @@ -12,6 +12,6 @@ __author__ = "Christian Tremblay, Stuart Longland, @sudo-Whateverman, Igor" __author_email__ = "christian.tremblay@servisys.com" -__version__ = "0.92.10" +__version__ = "0.92.11" __license__ = "Apache 2.0" __copyright__ = "Christian Tremblay / SERVISYS inc. | Stuart Longland / VRT | 2016"