fromJson static method
Returns a new SupervisorDevice instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static SupervisorDevice? fromJson(dynamic value) {
if (value is Map) {
final json = value.cast<String, dynamic>();
// Ensure that the map contains the required keys.
// Note 1: the values aren't checked for validity beyond being non-null.
// Note 2: this code is stripped in release mode!
assert(() {
requiredKeys.forEach((key) {
assert(json.containsKey(key),
'Required key "SupervisorDevice[$key]" is missing from JSON.');
assert(json[key] != null,
'Required key "SupervisorDevice[$key]" has a null value in JSON.');
});
return true;
}());
return SupervisorDevice(
apiPort: json[r'api_port'] == null
? null
: num.parse(json[r'api_port'].toString()),
ipAddress: mapValueOfType<String>(json, r'ip_address'),
commit: mapValueOfType<String>(json, r'commit'),
status: mapValueOfType<String>(json, r'status'),
downloadProgress: json[r'download_progress'] == null
? null
: num.parse(json[r'download_progress'].toString()),
osVersion: mapValueOfType<String>(json, r'os_version'),
supervisorVersion: mapValueOfType<String>(json, r'supervisor_version'),
updatePending: mapValueOfType<bool>(json, r'update_pending'),
updateDownloaded: mapValueOfType<bool>(json, r'update_downloaded'),
updateFailed: mapValueOfType<bool>(json, r'update_failed'),
);
}
return null;
}