-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDLDevice.m
52 lines (44 loc) · 1.58 KB
/
DLDevice.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// DLDevice.m
// PenguinSample
//
// Created on 11/3/14.
// Copyright (c) 2014 AT&T. All rights reserved.
//
#import "DLDevice.h"
@implementation DLDevice
- (instancetype)initWithDeviceDict:(NSDictionary *)dict
{
self = [super init];
if (self) {
if (dict) {
// convert the attributes array into a dictionary with label values as keys
NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
NSArray *rawAttributeList = dict[@"attributes"];
[rawAttributeList enumerateObjectsUsingBlock:^(NSDictionary *attributeDict, NSUInteger idx, BOOL *stop) {
[attributes setObject:attributeDict forKey:attributeDict[@"label"]];
}];
// gather the info we need from the device
_deviceGuid = dict[@"deviceGuid"];
_deviceType = dict[@"deviceType"];
_deviceName = attributes[@"name"][@"value"];
_attributes = attributes;
}
}
return self;
}
- (void)updateWithMessage:(NSDictionary *)message
{
[self.attributes enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
if ([key isEqualToString:message[@"label"]]) {
NSMutableDictionary *attributeDict = [obj mutableCopy];
attributeDict[@"value"] = message[@"value"];
self.attributes[key] = attributeDict;
}
}];
// also check to see if these are the pending changes we are expecting
if ([message[@"label"] isEqualToString:self.pendingChangeLabel]) {
self.pendingChangeLabel = nil;
}
}
@end