Fix several cases where the UI did not properly reflect model changes.
[enjoyable.git] / Classes / NJDevice.m
index e4c6b3d..bf39251 100644 (file)
@@ -72,16 +72,23 @@ static NSArray *InputsForElement(IOHIDDeviceRef device, id parent) {
         _vendorId = [(__bridge NSNumber *)IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDVendorIDKey)) intValue];
         _productId = [(__bridge NSNumber *)IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDProductIDKey)) intValue];
         self.children = InputsForElement(dev, self);
+        self.index = 1;
     }
     return self;
 }
 
+- (BOOL)isEqual:(id)object {
+    return [object isKindOfClass:NJDevice.class]
+        && [[(NJDevice *)object productName] isEqualToString:self.productName]
+        && [(NJDevice *)object index] == self.index;
+}
+
 - (NSString *)name {
     return [NSString stringWithFormat:@"%@ #%d", _productName, _index];
 }
 
 - (NSString *)uid {
-    return [NSString stringWithFormat: @"%d:%d:%d", _vendorId, _productId, _index];
+    return [NSString stringWithFormat:@"%d:%d:%d", _vendorId, _productId, _index];
 }
 
 - (NJInput *)findInputByCookie:(IOHIDElementCookie)cookie {