Skip to content

Commit

Permalink
Merge pull request #20 from cuplsensor/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
malcolmmackay committed Aug 1, 2020
2 parents 2057e40 + 1714c35 commit 06ff71e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setuptools.setup(
name="cuplcodec",
version="2.0.3",
version="2.0.4",
author="Malcolm Mackay",
author_email="malcolm@plotsensor.com",
description="Package for creating and decoding URLs that contain temperature and humidity samples.",
Expand Down
62 changes: 62 additions & 0 deletions wscodec/encoder/pyencoder/encoderfactory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from datetime import datetime
from .instrumented import InstrumentedSampleT, InstrumentedSampleTRH, InstrumentedSample


def encode(format,
serial,
secretkey,
baseurl,
smplintervalmins,
resetsalltime,
batteryadc,
resetcause,
usehmac,
httpsdisable,
tagerror) -> InstrumentedSample:
"""
Python-wrapped encoder factory.
Returns
--------
InstrumentedSample
An object containing a list of timestamped environmental sensor samples.
"""

encoder = _get_encoder(format)(serial=serial,
secretkey=secretkey,
baseurl=baseurl,
smplintervalmins=smplintervalmins,
resetsalltime=resetsalltime,
batteryadc=batteryadc,
resetcause=resetcause,
usehmac=usehmac,
httpsdisable=httpsdisable,
tagerror=tagerror,
format=format)
return encoder


def _get_encoder(format: int):
"""
Parameters
-----------
formatcode:
Value of the codec format field. Specifies which decoder shall be returned.
Return
-------
Decoder class for the given format code.
"""
encoders = {
InstrumentedSampleTRH.FORMAT_HDC2021_TRH: InstrumentedSampleTRH,
InstrumentedSampleT.FORMAT_HDC2021_TEMPONLY: InstrumentedSampleT
}
try:
encoder = encoders[format]
except KeyError:
# We need to test sending an unsupported format code.
encoder = encoders[InstrumentedSampleTRH.FORMAT_HDC2021_TRH]

return encoder
14 changes: 10 additions & 4 deletions wscodec/encoder/pyencoder/instrumented.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ def rhsample(self, countermax, counterstep):


class InstrumentedSampleT(InstrumentedSample):
FORMAT_HDC2021_TEMPONLY = 2

def __init__(self,
serial='ABCDEFGH',
secretkey='AAAACCCC11112222',
Expand All @@ -155,14 +157,15 @@ def __init__(self,
resetcause=0,
usehmac=True,
httpsdisable=False,
tagerror=False
tagerror=False,
format=FORMAT_HDC2021_TEMPONLY
):
super(InstrumentedSampleT, self).__init__(baseurl,
serial,
secretkey,
smplintervalmins,
batteryadc=batteryadc,
format=2,
format=format,
resetsalltime=resetsalltime,
usehmac=usehmac,
httpsdisable=httpsdisable)
Expand All @@ -179,6 +182,8 @@ def pushsamples(self, num):


class InstrumentedSampleTRH(InstrumentedSample):
FORMAT_HDC2021_TRH = 1

def __init__(self,
serial='ABCDEFGH',
secretkey='AAAACCCC11112222',
Expand All @@ -189,14 +194,15 @@ def __init__(self,
resetcause=0,
usehmac=True,
httpsdisable=False,
tagerror=False
tagerror=False,
format=FORMAT_HDC2021_TRH
):
super(InstrumentedSampleTRH, self).__init__(baseurl,
serial,
secretkey,
smplintervalmins,
batteryadc=batteryadc,
format=1,
format=format,
resetsalltime=resetsalltime,
usehmac=usehmac,
httpsdisable=httpsdisable)
Expand Down

0 comments on commit 06ff71e

Please sign in to comment.