Skip to content

Commit

Permalink
Removed the hardcoded true on subscribeWithQeuue
Browse files Browse the repository at this point in the history
- Removed mEventNumber.SetValue on MTRSubscribeParams
- Added the wildcard handling as nil for Darwin API
- Removed the casts on descriptions
  • Loading branch information
ready2die4u committed Jan 26, 2023
1 parent 8f5d5fa commit 4957f01
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,11 @@ class SubscribeEvent : public ModelCommand {
}

if (strcmp(GetName(), "subscribe-event-by-id") == 0) {
[device subscribeToEventsWithEndpointID:[NSNumber numberWithUnsignedShort:endpointId]
clusterID:[NSNumber numberWithUnsignedInteger:mClusterId]
eventID:[NSNumber numberWithUnsignedInteger:mEventId]
[device subscribeToEventsWithEndpointID:(endpointId == chip::kInvalidEndpointId)
? nil
: [NSNumber numberWithUnsignedShort:endpointId]
clusterID:(mClusterId == chip::kInvalidClusterId) ? nil : [NSNumber numberWithUnsignedInteger:mClusterId]
eventID:(mEventId == chip::kInvalidEventId) ? nil : [NSNumber numberWithUnsignedInteger:mEventId]
params:params
queue:callbackQueue
reportHandler:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
Expand Down Expand Up @@ -331,22 +333,23 @@ class ReadEvent : public ModelCommand {
params.minimumEventNumber = [NSNumber numberWithUnsignedLongLong:mEventNumber.Value()];
}

[device readEventsWithEndpointID:[NSNumber numberWithUnsignedShort:endpointId]
clusterID:[NSNumber numberWithUnsignedInteger:mClusterId]
eventID:[NSNumber numberWithUnsignedInteger:mEventId]
params:params
queue:callbackQueue
completion:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
if (error != nil) {
LogNSError("Error reading event", error);
}
if (values) {
for (id item in values) {
NSLog(@"Response Item: %@", [item description]);
}
[device
readEventsWithEndpointID:(endpointId == chip::kInvalidEndpointId) ? nil : [NSNumber numberWithUnsignedShort:endpointId]
clusterID:(mClusterId == chip::kInvalidClusterId) ? nil : [NSNumber numberWithUnsignedInteger:mClusterId]
eventID:(mEventId == chip::kInvalidEventId) ? nil : [NSNumber numberWithUnsignedInteger:mEventId]
params:params
queue:callbackQueue
completion:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
if (error != nil) {
LogNSError("Error reading event", error);
}
if (values) {
for (id item in values) {
NSLog(@"Response Item: %@", [item description]);
}
SetCommandExitStatus(error);
}];
}
SetCommandExitStatus(error);
}];
return CHIP_NO_ERROR;
}

Expand Down
19 changes: 7 additions & 12 deletions src/darwin/Framework/CHIP/MTRBaseDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ - (void)subscribeWithQueue:(dispatch_queue_t)queue
auto attributePath = std::make_unique<AttributePathParams>();
auto eventPath = std::make_unique<EventPathParams>();
// We want to get event reports at the minInterval, not the maxInterval.
eventPath->mIsUrgentEvent = true;
ReadPrepareParams readParams(session.Value());
[params toReadPrepareParams:readParams];
readParams.mpAttributePathParamsList = attributePath.get();
Expand Down Expand Up @@ -1693,9 +1692,7 @@ - (void)subscribeToEventsWithEndpointID:(NSNumber * _Nullable)endpointID
if (eventID) {
container.eventPathParams->mEventId = static_cast<chip::EventId>([eventID unsignedLongValue]);
}
if (params.reportEventsUrgently) {
container.eventPathParams->mIsUrgentEvent = params.reportEventsUrgently;
}
container.eventPathParams->mIsUrgentEvent = params.reportEventsUrgently;

app::InteractionModelEngine * engine = app::InteractionModelEngine::GetInstance();
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down Expand Up @@ -1869,8 +1866,8 @@ - (instancetype)initWithPath:(const ConcreteClusterPath &)path

- (NSString *)description
{
return [NSString stringWithFormat:@"<MTRClusterPath> endpoint %u cluster %u", (uint16_t) _endpoint.unsignedShortValue,
(uint32_t) _cluster.unsignedLongValue];
return [NSString
stringWithFormat:@"<MTRClusterPath> endpoint %u cluster %u", _endpoint.unsignedShortValue, _cluster.unsignedLongValue];
}

+ (instancetype)clusterPathWithEndpointID:(NSNumber *)endpointID clusterID:(NSNumber *)clusterID
Expand Down Expand Up @@ -1917,9 +1914,8 @@ - (instancetype)initWithPath:(const ConcreteDataAttributePath &)path

- (NSString *)description
{
return [NSString stringWithFormat:@"<MTRAttributePath> endpoint %u cluster %u attribute %u",
(uint16_t) self.endpoint.unsignedShortValue, (uint32_t) self.cluster.unsignedLongValue,
(uint32_t) _attribute.unsignedLongValue];
return [NSString stringWithFormat:@"<MTRAttributePath> endpoint %u cluster %u attribute %u", self.endpoint.unsignedShortValue,
self.cluster.unsignedLongValue, _attribute.unsignedLongValue];
}

+ (instancetype)attributePathWithEndpointID:(NSNumber *)endpointID
Expand Down Expand Up @@ -1977,9 +1973,8 @@ - (instancetype)initWithPath:(const ConcreteEventPath &)path

- (NSString *)description
{
return
[NSString stringWithFormat:@"<MTREventPath> endpoint %u cluster %u event %u", (uint16_t) self.endpoint.unsignedShortValue,
(uint32_t) self.cluster.unsignedLongValue, (uint32_t) _event.unsignedLongValue];
return [NSString stringWithFormat:@"<MTREventPath> endpoint %u cluster %u event %u", self.endpoint.unsignedShortValue,
self.cluster.unsignedLongValue, _event.unsignedLongValue];
}

+ (instancetype)eventPathWithEndpointID:(NSNumber *)endpointID clusterID:(NSNumber *)clusterID eventID:(NSNumber *)eventID
Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* If nil (the default value), all of the queued events will be reported from lowest to highest event number.
*
* If not nil, queued events with an event number smaller than eventMin will not be reported.
* If not nil, queued events with an event number smaller than minimumEventNumber will not be reported.
*/
@property (nonatomic, copy, nullable) NSNumber * minimumEventNumber MTR_NEWLY_AVAILABLE;

Expand Down
3 changes: 0 additions & 3 deletions src/darwin/Framework/CHIP/MTRCluster.mm
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ - (void)toReadPrepareParams:(chip::app::ReadPrepareParams &)readPrepareParams
readPrepareParams.mMinIntervalFloorSeconds = self.minInterval.unsignedShortValue;
readPrepareParams.mMaxIntervalCeilingSeconds = self.maxInterval.unsignedShortValue;
readPrepareParams.mKeepSubscriptions = !self.replaceExistingSubscriptions;
if (self.minimumEventNumber) {
readPrepareParams.mEventNumber.SetValue(static_cast<chip::EventNumber>([self.minimumEventNumber unsignedLongLongValue]));
}
}

@end
Expand Down

0 comments on commit 4957f01

Please sign in to comment.