Skip to content
Merged
Show file tree
Hide file tree
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: 5 additions & 8 deletions lib/speck.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ defmodule Speck do
}
end

opts[:optional] && is_nil(raw_value) && type == :boolean ->
{
Map.put(fields, name, false),
errors,
make_meta(name, field_status, raw_value)
}

is_nil(opts[:optional]) && is_nil(raw_value) ->
{
fields,
Expand All @@ -72,7 +65,11 @@ defmodule Speck do
}

opts[:optional] && is_nil(raw_value) ->
{fields, errors, make_meta(name, field_status, raw_value)}
{
Map.put(fields, name, nil),
errors,
make_meta(name, field_status, raw_value)
}

is_list(type) ->
raw_value
Expand Down
9 changes: 5 additions & 4 deletions test/speck_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule Speck.Test do
"type" => "air_quality",
"rs485_address" => "5",
"serial_number" => "DEVICE1234567890",
# wifi_ssid => not present
# low_power_mode => not present
"dns_servers" => [
"1.1.1.1",
Expand Down Expand Up @@ -34,7 +35,7 @@ defmodule Speck.Test do
rs485_address: 5,
serial_number: "DEVICE1234567890",
wifi_ssid: nil,
low_power_mode: false,
low_power_mode: nil,
dns_servers: [
"1.1.1.1",
"1.0.0.1",
Expand Down Expand Up @@ -702,8 +703,8 @@ defmodule Speck.Test do
attribute_5: 5
},
list_attribute_1: [
%{},
%{attribute_9: 9}
%{attribute_9: nil},
%{attribute_9: 9},
],
list_attribute_2: []
}
Expand Down Expand Up @@ -767,7 +768,7 @@ defmodule Speck.Test do
partially_known_nested: %{
attribute_5: 5
},
list_attribute_1: [%{}],
list_attribute_1: [%{attribute_9: nil}],
list_attribute_2: []
}

Expand Down