Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize transmitter_time according to SOS Access v4 doc. #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion sos_access/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ class SOSAccessRequest:

pass

# Custom DateTime field with specific format to match SOS Access v4 spec, 0/23 char. Ex.”2002-05-28 11:35:20.022”
class TransmitterDateTime(marshmallow.fields.DateTime):
def _serialize(self, value, attr, obj, **kwargs):
if value is None:
return None
return value.strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]

def _deserialize(self, value, attr, data, **kwargs):
if value is None:
return None
return super()._deserialize(value, attr, data, **kwargs)

class AlarmRequest(SOSAccessRequest):

Expand Down Expand Up @@ -315,7 +326,7 @@ class AlarmRequestSchema(SOSAccessSchema):
receiver = marshmallow.fields.String(
required=True, validate=[Length(min=1, max=20)]
)
transmitter_time = marshmallow.fields.DateTime(
transmitter_time = TransmitterDateTime(
allow_none=True, data_key="transmittertime"
)
alarm_type = marshmallow.fields.String(
Expand Down