-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from cuplsensor/dev
Dev
- Loading branch information
Showing
3 changed files
with
73 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters