Skip to content

Commit

Permalink
fix: replace still existing usages of 'writable' with readOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpeintner committed Jan 9, 2019
1 parent 96c37f6 commit 85e9cd7
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 44 deletions.
4 changes: 2 additions & 2 deletions packages/binding-coap/src/coap-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export default class CoapServer implements ProtocolServer {
}
// writeproperty
} else if (req.method === "PUT") {
if (property.writable) {
if (!property.readOnly) {
let value;
try {
value = ContentSerdes.get().contentToValue({ type: contentType, body: req.payload }, <any>property);
Expand All @@ -259,7 +259,7 @@ export default class CoapServer implements ProtocolServer {
});
} else {
res.code = "4.00";
res.end("Property Not Writable");
res.end("Property readOnly");
}
} else {
res.code = "4.05";
Expand Down
4 changes: 2 additions & 2 deletions packages/binding-http/src/http-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export default class HttpServer implements ProtocolServer {
res.end(err.message);
});
} else if (req.method === "PUT") {
if (property.writable) {
if (!property.readOnly) {
// load payload
let body: Array<any> = [];
req.on("data", (data) => { body.push(data) });
Expand Down Expand Up @@ -352,7 +352,7 @@ export default class HttpServer implements ProtocolServer {
});
} else {
res.writeHead(400);
res.end("Property Not Writable");
res.end("Property readOnly");
}
} else {
res.writeHead(405);
Expand Down
2 changes: 1 addition & 1 deletion packages/binding-http/test/http-server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class HttpServerTest {

let testThing = new ExposedThing(null);
testThing.name = "Test";
testThing.addProperty("test", { writable: true, type: "string" }, "off");
testThing.addProperty("test", { type: "string" }, "off");
testThing.properties.test.forms = [];
testThing.addAction("try", { output: { type: "string" }}, (input) => { return new Promise<string>( (resolve, reject) => { resolve("TEST"); }); });
testThing.actions.try.forms = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/binding-oracle/src/oracle-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export default class OracleServer implements ProtocolServer {
tupples.forEach( (tupple: any) => {
if (thing.properties[tupple.attribute.id] !== undefined) {
console.info(`### Thing '${thing.name}' has Property '${tupple.attribute.id}' for writing '${tupple.newValue}'`);
if (thing.properties[tupple.attribute.id].writable) {
if (!thing.properties[tupple.attribute.id].readOnly) {
thing.properties[tupple.attribute.id]
.write(tupple.newValue)
.catch((err: any) => { console.error("Property write error: " + err) });
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/cli-default-servient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export default class DefaultServient extends Servient {
.addProperty(
"things",
{
writable: true,
observable: false,
type: "string"
})
Expand Down
11 changes: 6 additions & 5 deletions packages/core/src/exposed-thing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ export default class ExposedThing extends TD.Thing implements WoT.ExposedThing {
// in case of function instead of lambda, the handler is bound to a scope shared with the readHandler in PropertyState
this.properties[propertyName].getState().writeHandler = handler.bind(this.properties[propertyName].getState().scope);

// setting write handler implies Property is writable
if (!this.properties[propertyName].writable) {
console.warn(`ExposedThing '${this.name}' automatically making Property '${propertyName}' writable`);
this.properties[propertyName].writable = true;
// setting write handler implies Property is writable (readOnly == false)
if (this.properties[propertyName].readOnly) {
console.warn(`ExposedThing '${this.name}' automatically setting Property '${propertyName}' readOnly to false`);
this.properties[propertyName].readOnly = false;
}
} else {
throw new Error(`ExposedThing '${this.name}' has no Property '${propertyName}'`);
Expand Down Expand Up @@ -249,7 +249,8 @@ class ExposedThingProperty extends TD.ThingProperty implements WoT.ThingProperty
}).getInternalState;

// apply defaults
this.writable = false;
this.readOnly = false;
this.writeOnly = false;
this.observable = false;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/ClientTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ let myThingDesc = {
properties: {
aProperty: {
type: "integer",
writable: true,
readOnly: false,
forms: [
{ href: "testdata://host/athing/properties/aproperty", mediaType: "application/json" }
]
Expand Down
16 changes: 3 additions & 13 deletions packages/core/test/ServerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,12 @@ class WoTServerTest {
@test async "should be able to add a property with default value 0"() {
let thing: WoT.ExposedThing = WoTServerTest.WoT.produce({ name: "ThingWith1" });
let initp: WoT.PropertyFragment = {
writable: true,
type: "number"
};
thing.addProperty("number", initp, 1);

expect(thing.properties).to.have.property("number");
expect(thing.properties.number).to.have.property("writable").that.equals(true);
expect(thing.properties.number).to.have.property("readOnly").that.equals(false);
expect(thing.properties.number).to.have.property("observable").that.equals(false);

let value1 = await thing.properties.number.read();
Expand All @@ -133,13 +132,12 @@ class WoTServerTest {
@test async "should be able to add a property with default value XYZ"() {
let thing: WoT.ExposedThing = WoTServerTest.WoT.produce({ name: "ThingWithXYZ" });
let initp: WoT.PropertyFragment = {
writable: true,
type: "string"
};
thing.addProperty("string", initp, "XYZ");

expect(thing.properties).to.have.property("string");
expect(thing.properties.string).to.have.property("writable").that.equals(true);
expect(thing.properties.string).to.have.property("readOnly").that.equals(false);
expect(thing.properties.string).to.have.property("observable").that.equals(false);

let value1 = await thing.properties.string.read();
Expand All @@ -149,13 +147,12 @@ class WoTServerTest {
@test async "should be able to add a property without any default value"() {
let thing: WoT.ExposedThing = WoTServerTest.WoT.produce({ name: "ThingWithNothing" });
let initp: WoT.PropertyFragment = {
writable: true,
type: "number"
};
thing.addProperty("null", initp);

expect(thing.properties).to.have.property("null");
expect(thing.properties.null).to.have.property("writable").that.equals(true);
expect(thing.properties.null).to.have.property("readOnly").that.equals(false);
expect(thing.properties.null).to.have.property("observable").that.equals(false);

let value1 = await thing.properties.null.read();
Expand All @@ -165,7 +162,6 @@ class WoTServerTest {
@test async "should be able to read and write Property locally"() {
let thing: WoT.ExposedThing = WoTServerTest.WoT.produce({ name: "thing3" });
let initp: WoT.PropertyFragment = {
writable: true,
type: "number"
};
thing.addProperty("number", initp, 10);
Expand All @@ -181,7 +177,6 @@ class WoTServerTest {
@test async "should be able to read Property with read handler (incrementing with lambda)"() {
let thing: WoT.ExposedThing = WoTServerTest.WoT.produce({ name: "otherthingIncRead" });
let initp: WoT.PropertyFragment = {
writable: true,
type: "number"
};
let counter: number = 0;
Expand All @@ -202,7 +197,6 @@ class WoTServerTest {
@test async "should be able to read Property with read handler (incrementing with function)"() {
let thing: WoT.ExposedThing = WoTServerTest.WoT.produce({ name: "otherthingIncRead2" });
let initp: WoT.PropertyFragment = {
writable: true,
type: "number"
};
let counter: number = 0;
Expand All @@ -223,7 +217,6 @@ class WoTServerTest {
@test async "should be able to read Property with read handler (incrementing with handler scope state)"() {
let thing: WoT.ExposedThing = WoTServerTest.WoT.produce({ name: "otherthingIncRead3" });
let initp: WoT.PropertyFragment = {
writable: true,
type: "number"
};
thing.addProperty("number", initp).setPropertyReadHandler(
Expand Down Expand Up @@ -251,7 +244,6 @@ class WoTServerTest {
@test async "should be able to write Property with write handler (summing)"() {
let thing: WoT.ExposedThing = WoTServerTest.WoT.produce({ name: "otherthingReadWrite" });
let initp: WoT.PropertyFragment = {
writable: true,
type: "number"
};
thing.addProperty("number", initp, 2);
Expand Down Expand Up @@ -294,12 +286,10 @@ class WoTServerTest {
@test async "should be able to write Property from any write handler (doubling)"() {
let thing: WoT.ExposedThing = WoTServerTest.WoT.produce({ name: "otherthingWrite" });
let initp: WoT.PropertyFragment = {
writable: true,
type: "number"
};
thing.addProperty("number", initp);
let initp2: WoT.PropertyFragment = {
writable: true,
type: "number"
};
thing.addProperty("number2", initp2);
Expand Down
14 changes: 7 additions & 7 deletions packages/demo-servients/src/fujitsu-local-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ servient.start().then(async (WoT) => {
console.info(thing.name + " produced");

thing
.addProperty("PumpStatus", { type: "boolean", writable: false }, false)
.addProperty("ValveStatus", { type: "boolean", writable: false }, false)
.addProperty("PumpStatus", { type: "boolean", readOnly: true }, false)
.addProperty("ValveStatus", { type: "boolean", readOnly: true }, false)

// upper tank (102)
.addProperty("Tank102LevelValue", { type: "number", writable: false }, 0.0)
.addProperty("Tank102OverflowStatus", { type: "boolean", writable: false }, false)
.addProperty("Tank102LevelValue", { type: "number", readOnly: true }, 0.0)
.addProperty("Tank102OverflowStatus", { type: "boolean", readOnly: true }, false)

// lower tank (101)
.addProperty("Tank101MaximumLevelStatus", { type: "boolean", writable: false }, false)
.addProperty("Tank101MinimumLevelStatus", { type: "boolean", writable: false }, false)
.addProperty("Tank101OverflowStatus", { type: "boolean", writable: false }, false)
.addProperty("Tank101MaximumLevelStatus", { type: "boolean", readOnly: true }, false)
.addProperty("Tank101MinimumLevelStatus", { type: "boolean", readOnly: true }, false)
.addProperty("Tank101OverflowStatus", { type: "boolean", readOnly: true }, false)

// actuators
.addAction("StartPump", {}, () => {
Expand Down
14 changes: 7 additions & 7 deletions packages/demo-servients/src/oracle-festo-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,17 @@ servient.start().then(async (WoT) => {

thing
// actuator state
.addProperty("PumpStatus", { type: "boolean", writable: false }, false)
.addProperty("ValveStatus", { type: "boolean", writable: false }, false)
.addProperty("PumpStatus", { type: "boolean", readOnly: true }, false)
.addProperty("ValveStatus", { type: "boolean", readOnly: true }, false)

// upper tank (102)
.addProperty("Tank102LevelValue", { type: "number", writable: false }, 0.0)
.addProperty("Tank102OverflowStatus", { type: "boolean", writable: false }, false)
.addProperty("Tank102LevelValue", { type: "number", readOnly: true }, 0.0)
.addProperty("Tank102OverflowStatus", { type: "boolean", readOnly: true }, false)

// lower tank (101)
.addProperty("Tank101MaximumLevelStatus", { type: "boolean", writable: false }, false)
.addProperty("Tank101MinimumLevelStatus", { type: "boolean", writable: false }, false)
.addProperty("Tank101OverflowStatus", { type: "boolean", writable: false }, false)
.addProperty("Tank101MaximumLevelStatus", { type: "boolean", readOnly: true }, false)
.addProperty("Tank101MinimumLevelStatus", { type: "boolean", readOnly: true }, false)
.addProperty("Tank101OverflowStatus", { type: "boolean", readOnly: true }, false)

// actuators
.addAction("StartPump", {}, () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/demo-servients/src/raspberry-servient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ function main() {
{
type: "integer",
minimum: 0,
maximum: 255,
writable: true
maximum: 255
},
100
)
Expand All @@ -104,8 +103,7 @@ function main() {
r: { type: "integer", minimum: 0, maximum: 255 },
g: { type: "integer", minimum: 0, maximum: 255 },
b: { type: "integer", minimum: 0, maximum: 255 },
},
writable: true
}
},
{ r: 0, g: 0, b: 0 }
)
Expand Down

0 comments on commit 85e9cd7

Please sign in to comment.