forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a way to ask Matter.framework for information about device types. (…
- Loading branch information
1 parent
064c205
commit 579b1b1
Showing
11 changed files
with
442 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import <Matter/MTRDefines.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
MTR_NEWLY_AVAILABLE | ||
@interface MTRDeviceType : NSObject | ||
|
||
/** | ||
* Returns an MTRDeviceType for the given ID, if the ID is known. Returns nil | ||
* for unknown IDs. | ||
*/ | ||
+ (nullable MTRDeviceType *)deviceTypeForID:(NSNumber *)deviceTypeID; | ||
|
||
/** | ||
* The identifier of the device type (32-bit unsigned integer). | ||
*/ | ||
@property (nonatomic, readonly, copy) NSNumber * id; | ||
|
||
/** | ||
* Returns the name of the device type. | ||
*/ | ||
@property (nonatomic, readonly, retain) NSString * name; | ||
|
||
/** | ||
* Returns whether this is a utility device type. | ||
*/ | ||
@property (nonatomic, readonly, assign) BOOL isUtility; | ||
|
||
- (instancetype)init NS_UNAVAILABLE; | ||
+ (instancetype)new NS_UNAVAILABLE; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#import <Matter/MTRDeviceType.h> | ||
|
||
#import "MTRDeviceTypeMetadata.h" | ||
#import "MTRLogging_Internal.h" | ||
|
||
#include <lib/support/SafeInt.h> | ||
|
||
using namespace chip; | ||
|
||
@implementation MTRDeviceType | ||
|
||
- (nullable instancetype)initWithDeviceTypeID:(NSNumber *)id name:(NSString *)name isUtility:(BOOL)isUtility | ||
{ | ||
if (!(self = [super init])) { | ||
return nil; | ||
} | ||
|
||
_id = id; | ||
_name = name; | ||
_isUtility = isUtility; | ||
return self; | ||
} | ||
|
||
+ (nullable MTRDeviceType *)deviceTypeForID:(NSNumber *)deviceTypeID | ||
{ | ||
if (!CanCastTo<DeviceTypeId>(deviceTypeID.unsignedLongLongValue)) { | ||
MTR_LOG_ERROR("Invalid device type ID: 0x%llx", deviceTypeID.unsignedLongLongValue); | ||
return nil; | ||
} | ||
|
||
auto * deviceTypeData = MTRDeviceTypeDataForID(static_cast<DeviceTypeId>(deviceTypeID.unsignedLongLongValue)); | ||
if (!deviceTypeData) { | ||
return nil; | ||
} | ||
|
||
return [[MTRDeviceType alloc] | ||
initWithDeviceTypeID:deviceTypeID | ||
name:[NSString stringWithUTF8String:deviceTypeData->name] | ||
isUtility:(deviceTypeData->deviceClass != MTRDeviceTypeClass::Simple)]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/darwin/Framework/CHIP/zap-generated/MTRClusterConstants.h
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.