Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(binding-coap): remove cov:observe subprotocol #1315

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions packages/binding-coap/src/coap-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { MdnsIntroducer } from "./mdns-introducer";
import { PropertyElement, DataSchema, ActionElement, EventElement } from "wot-thing-description-types";
import { CoapServerConfig } from "./coap";
import { DataSchemaValue } from "wot-typescript-definitions";
import { filterPropertyObserveOperations, getPropertyOpValues } from "./util";
import { getPropertyOpValues } from "./util";

const { debug, warn, info, error } = createLoggers("binding-coap", "coap-server");

Expand Down Expand Up @@ -248,23 +248,14 @@ export default class CoapServer implements ProtocolServer {
continue;
}

let subprotocol: string | undefined;

const observeOpValues = filterPropertyObserveOperations(formOpValues);

if (observeOpValues.length > 0) {
subprotocol = "cov:observe";
}

const form = this.createAffordanceForm(
base,
this.PROPERTY_DIR,
offeredMediaType,
formOpValues,
thing.uriVariables,
propertyName,
property.uriVariables,
subprotocol
property.uriVariables
);

this.addFormToAffordance(form, property);
Expand Down Expand Up @@ -299,8 +290,7 @@ export default class CoapServer implements ProtocolServer {
["subscribeevent", "unsubscribeevent"],
thing.uriVariables,
eventName,
event.uriVariables,
"cov:observe"
event.uriVariables
);

this.addFormToAffordance(form, event);
Expand Down
7 changes: 3 additions & 4 deletions packages/binding-coap/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ export function filterEventOperations(opValues: string[]) {
/**
* Function to (potentially) generate two arrays of `op` values: One with the
* values "readproperty" and "writeproperty", and one with
* "observerproperty" and "unobserveproperty".
* "observeproperty" and "unobserveproperty".
*
* This CoAP-specific distinction is made to be able to generate
* separate forms for the observe-related operations, where the addition
* of a `subprotocol` field with a value of `cov:observe` has to be added.
* This distinction is made to be able to generate separate forms for the
* observe-related operations.
*
* @param property The property for which the forms are going to be
* generated.
Expand Down
12 changes: 7 additions & 5 deletions packages/binding-coap/test/coap-server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ class CoapServerTest {
await coapServer.stop();
}

@test async "should add the cov:observe subprotocol value to observable properties and events "() {
@test async "should add the correct operation types to observable properties and events "() {
const coapServer = new CoapServer({ port: 5683 });
const servient = new Servient();
servient.addServer(coapServer);
Expand Down Expand Up @@ -679,7 +679,6 @@ class CoapServerTest {

if (observeOpValuePresent) {
observeOpValueFormCount++;
expect(form.subprotocol).to.eql("cov:observe");
}

const readWriteOpValueCount = filterPropertyReadWriteOperations(
Expand All @@ -703,14 +702,17 @@ class CoapServerTest {
for (const event of Object.values(td.events!)) {
for (const form of event.forms) {
const opValues = form.op!;
expect(opValues.length > 0);
// eslint-disable-next-line no-unused-expressions
expect(opValues.length > 0).to.be.true;

const eventOpValueCount = filterEventOperations(opValues as Array<string>).length;
const eventOpValueCountPresent = eventOpValueCount > 0;

expect(eventOpValueCountPresent);
// eslint-disable-next-line no-unused-expressions
expect(eventOpValueCountPresent).to.be.true;

expect(form.subprotocol === "cov:observe");
// eslint-disable-next-line no-unused-expressions
expect(form.subprotocol === "cov:observe").to.be.false;
}
}

Expand Down
Loading