Skip to content

Commit

Permalink
Merge pull request #1315 from JKRhb/coap-update
Browse files Browse the repository at this point in the history
feat(binding-coap): remove cov:observe subprotocol
  • Loading branch information
JKRhb authored Aug 15, 2024
2 parents 2f88743 + a5b4711 commit f63b729
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
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

0 comments on commit f63b729

Please sign in to comment.