Skip to content

Commit

Permalink
Log when MTRServerAttribute not bound to a controller has its value u…
Browse files Browse the repository at this point in the history
…pdated. (#31973)

This should enable API consumers to more easily figure out why their attribute
updates are not being published.
  • Loading branch information
bzbarsky-apple authored Feb 8, 2024
1 parent 1ad0e12 commit 0748472
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/darwin/Framework/CHIP/ServerEndpoint/MTRServerAttribute.mm
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,19 @@ - (nullable instancetype)initWithAttributeID:(NSNumber *)attributeID value:(NSDi
_parentCluster = app::ConcreteClusterPath(kInvalidEndpointId, kInvalidClusterId);

// Now call setValue to store the value and its serialization.
if ([self setValue:value] == NO) {
if ([self setValueInternal:value logIfNotAssociated:NO] == NO) {
return nil;
}

return self;
}

- (BOOL)setValue:(NSDictionary<NSString *, id> *)value
{
return [self setValueInternal:value logIfNotAssociated:YES];
}

- (BOOL)setValueInternal:(NSDictionary<NSString *, id> *)value logIfNotAssociated:(BOOL)logIfNotAssociated
{
id serializedValue;
id dataType = value[MTRTypeKey];
Expand Down Expand Up @@ -121,7 +126,12 @@ - (BOOL)setValue:(NSDictionary<NSString *, id> *)value

MTRDeviceController * deviceController = _deviceController;
if (deviceController == nil) {
// We're not bound to a controller, so safe to directly update _serializedValue.
// We're not bound to a controller, so safe to directly update
// _serializedValue.
if (logIfNotAssociated) {
MTR_LOG_DEFAULT("Not publishing value for attribute " ChipLogFormatMEI "; not bound to a controller",
ChipLogValueMEI(static_cast<AttributeId>(_attributeID.unsignedLongLongValue)));
}
_serializedValue = serializedValue;
} else {
[deviceController asyncDispatchToMatterQueue:^{
Expand Down

0 comments on commit 0748472

Please sign in to comment.