Commit e88159f 1 parent 31a4b81 commit e88159f Copy full SHA for e88159f
File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -159,6 +159,15 @@ class MiotAction(MiotBaseModel):
159
159
inputs : Any = Field (alias = "in" )
160
160
outputs : Any = Field (alias = "out" )
161
161
162
+ @root_validator (pre = True )
163
+ def default_null_to_empty (cls , values ):
164
+ """Coerce null values for in&out to empty lists."""
165
+ if values ["in" ] is None :
166
+ values ["in" ] = []
167
+ if values ["out" ] is None :
168
+ values ["out" ] = []
169
+ return values
170
+
162
171
def fill_from_parent (self , service : "MiotService" ):
163
172
"""Overridden to convert inputs and outputs to property references."""
164
173
super ().fill_from_parent (service )
Original file line number Diff line number Diff line change @@ -138,6 +138,26 @@ def test_action():
138
138
assert act .plain_name == "dummy-action"
139
139
140
140
141
+ def test_action_with_nulls ():
142
+ """Test that actions with null ins and outs are parsed correctly."""
143
+ simple_action = """\
144
+ {
145
+ "iid": 1,
146
+ "type": "urn:miot-spec-v2:action:dummy-action:0000001:dummy:1",
147
+ "description": "Description",
148
+ "in": null,
149
+ "out": null
150
+ }"""
151
+ act = MiotAction .parse_raw (simple_action )
152
+ assert act .aiid == 1
153
+ assert act .urn .type == "action"
154
+ assert act .description == "Description"
155
+ assert act .inputs == []
156
+ assert act .outputs == []
157
+
158
+ assert act .plain_name == "dummy-action"
159
+
160
+
141
161
@pytest .mark .parametrize (
142
162
("urn_string" , "unexpected" ),
143
163
[
You can’t perform that action at this time.
0 commit comments