Skip to content

Commit

Permalink
format with prettier v2
Browse files Browse the repository at this point in the history
Signed-off-by: Hasan Eroglu <[email protected]>
  • Loading branch information
hasanheroglu committed Sep 27, 2024
1 parent c03e13a commit 41ed9c8
Show file tree
Hide file tree
Showing 40 changed files with 180 additions and 163 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actionsx/prettier@v3
- uses: actionsx/prettier@v2
with:
args: --check .
10 changes: 5 additions & 5 deletions mashups/smart-home/mashup-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ const wotHelper = new Helpers(servient);

// we will fetch the TDs of the devices
const coffeeMachineTD = (await wotHelper.fetch(
coffeeMachineURL,
coffeeMachineURL
)) as WoT.ThingDescription;
// Alternatively, this Thing self-hosts its TD at http://plugfest.thingweb.io:8081/coffee-machine that you can fetch
const presenceSensorTD = (await wotHelper.fetch(
`mqtt://${process.env.PRESENCE_SENSOR_BROKER_URI}/smart-home-presence-sensor`,
`mqtt://${process.env.PRESENCE_SENSOR_BROKER_URI}/smart-home-presence-sensor`
)) as WoT.ThingDescription;
const smartClockTD = (await wotHelper.fetch(
`coap://${process.env.SMART_CLOCK_HOSTNAME}:${process.env.SMART_CLOCK_PORT}/smart-home-smart-clock`,
`coap://${process.env.SMART_CLOCK_HOSTNAME}:${process.env.SMART_CLOCK_PORT}/smart-home-smart-clock`
)) as WoT.ThingDescription;

// consuming TDs allows creates a software object, which allows us to execute functions on them
Expand Down Expand Up @@ -79,7 +79,7 @@ const wotHelper = new Helpers(servient);
"Current time is " +
currentTime.hour.toString().padStart(2, "0") +
":" +
currentTime.minute.toString().padStart(2, "0"),
currentTime.minute.toString().padStart(2, "0")
);

// To avoid accidental brews, a flag is used to check whether a coffee was brewed before
Expand All @@ -101,6 +101,6 @@ const wotHelper = new Helpers(servient);
morningCoffeeFlag = false;
}
}, 1000);
},
}
);
})();
4 changes: 2 additions & 2 deletions mashups/smart-home/things/simple-coffee-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ servient.addServer(
new HttpServer({
baseUri: `http://${hostname}:${httpPort}`,
port: parseInt(httpPort),
}),
})
);

let waterAmount = 1000;
Expand Down Expand Up @@ -212,7 +212,7 @@ servient.start().then((WoT) => {
thing.expose().then(() => {
console.info(thing.getThingDescription().title + " ready");
console.info(
"TD available at http://" + hostname + ":" + httpPort,
"TD available at http://" + hostname + ":" + httpPort
);
});
})
Expand Down
2 changes: 1 addition & 1 deletion mashups/smart-home/things/smart-clock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ servient.addServer(
new CoapServer({
address: hostname,
port: parseInt(port),
}),
})
);

let minuteCounter = 0;
Expand Down
11 changes: 6 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
"eslint-plugin-unused-imports": "^4.1.4",
"eslint-plugin-workspaces": "^0.10.1",
"mocha": "^10.7.3",
"prettier": "^3.3.3"
"prettier": "^2.3.2"
}
}
26 changes: 13 additions & 13 deletions things/advanced-coffee-machine/http/ts/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let thingModel;

if (tmPath != null && tmPath !== "") {
thingModel = JSON.parse(
fs.readFileSync(path.join(__dirname, tmPath)).toString(),
fs.readFileSync(path.join(__dirname, tmPath)).toString()
);
}

Expand All @@ -99,7 +99,7 @@ servient.addServer(
new HttpServer({
baseUri: `http://${hostname}:${portNumber}`,
port: portNumber,
}),
})
);

servient
Expand All @@ -126,15 +126,15 @@ servient

thing.setPropertyReadHandler(
"allAvailableResources",
async () => allAvailableResources,
async () => allAvailableResources
);
thing.setPropertyReadHandler(
"possibleDrinks",
async () => possibleDrinks,
async () => possibleDrinks
);
thing.setPropertyReadHandler(
"maintenanceNeeded",
async () => maintenanceNeeded,
async () => maintenanceNeeded
);
thing.setPropertyReadHandler("schedules", async () => schedules);

Expand All @@ -150,7 +150,7 @@ servient
// (the notify function here simply logs a message to the console)
notify(
"[email protected]",
`maintenanceNeeded property has changed, new value is: ${maintenanceNeeded}`,
`maintenanceNeeded property has changed, new value is: ${maintenanceNeeded}`
);
}
});
Expand Down Expand Up @@ -181,7 +181,7 @@ servient
}
}
throw Error("Please specify id variable as uriVariables.");
},
}
);

// Override a read handler for availableResourceLevel property,
Expand All @@ -205,7 +205,7 @@ servient
}
}
throw Error("Please specify id variable as uriVariables.");
},
}
);

// Set up a handler for makeDrink action
Expand Down Expand Up @@ -291,30 +291,30 @@ servient
newResources.water -= Math.ceil(
quantity *
sizeQuantifiers[size] *
drinkRecipes[drinkId].water,
drinkRecipes[drinkId].water
);
newResources.milk -= Math.ceil(
quantity *
sizeQuantifiers[size] *
drinkRecipes[drinkId].milk,
drinkRecipes[drinkId].milk
);
newResources.chocolate -= Math.ceil(
quantity *
sizeQuantifiers[size] *
drinkRecipes[drinkId].chocolate,
drinkRecipes[drinkId].chocolate
);
newResources.coffeeBeans -= Math.ceil(
quantity *
sizeQuantifiers[size] *
drinkRecipes[drinkId].coffeeBeans,
drinkRecipes[drinkId].coffeeBeans
);

// Check if the amount of available resources is sufficient to make a drink
for (const resource in newResources) {
if (newResources[resource] <= 0) {
thing.emitEvent(
"outOfResource",
`Low level of ${resource}: ${newResources[resource]}%`,
`Low level of ${resource}: ${newResources[resource]}%`
);
return {
result: false,
Expand Down
2 changes: 1 addition & 1 deletion things/advanced-coffee-machine/http/ts/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("Client Tests", () => {
try {
const WoT = await servient.start();
const td: WoT.ThingDescription = await WoT.requestThingDescription(
`http://localhost:${port}/http-advanced-coffee-machine`,
`http://localhost:${port}/http-advanced-coffee-machine`
);
thing = await WoT.consume(td);
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions things/advanced-coffee-machine/http/ts/test/td.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("TD Test", () => {
response.on("end", () => {
try {
const result = JSON.parse(
Buffer.concat(body).toString(),
Buffer.concat(body).toString()
);
const valid =
validate && result !== ""
Expand All @@ -60,7 +60,7 @@ describe("TD Test", () => {
done(error);
}
});
},
}
);
});
});
2 changes: 1 addition & 1 deletion things/advanced-coffee-machine/tm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("Advanced Coffee Machine", () => {
validate = ajv.compile(tmSchema);
done();
});
},
}
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ function getFullTD(acceptType) {
) {
console.log(
"Thing Description (json):\n",
JSON.parse(res.payload.toString()),
JSON.parse(res.payload.toString())
);
} else {
const decodedData = cbor.decode(res.payload);
console.log(
"Thing Description (cbor):\n",
JSON.parse(decodedData),
JSON.parse(decodedData)
);
}
} else {
Expand Down Expand Up @@ -90,7 +90,7 @@ function getResult(acceptType) {
if (contentType.includes("application/json")) {
console.log(
"Result (json): ",
JSON.parse(res.payload.toString()),
JSON.parse(res.payload.toString())
);
} else {
const decodedData = cbor.decode(res.payload);
Expand Down Expand Up @@ -127,13 +127,13 @@ function observeResultProperty(acceptType) {
if (contentType.includes("application/json")) {
console.log(
"Observe result property (json): ",
JSON.parse(res.payload.toString()),
JSON.parse(res.payload.toString())
);
} else {
const decodedData = cbor.decode(res.payload);
console.log(
"Observe result property (cbor): ",
decodedData,
decodedData
);
}
} else {
Expand Down Expand Up @@ -167,7 +167,7 @@ function getLastChange(acceptType) {
if (contentType.includes("application/json")) {
console.log(
"Last Change (json): ",
JSON.parse(res.payload.toString()),
JSON.parse(res.payload.toString())
);
} else {
const decodedData = cbor.decode(res.payload);
Expand Down Expand Up @@ -204,13 +204,13 @@ function observeLastChangeProperty(acceptType) {
if (contentType.includes("application/json")) {
console.log(
"Observe lastChange property (json): ",
JSON.parse(res.payload.toString()),
JSON.parse(res.payload.toString())
);
} else {
const decodedData = cbor.decode(res.payload);
console.log(
"Observe lastChange property (cbor): ",
decodedData,
decodedData
);
}
} else {
Expand Down Expand Up @@ -243,7 +243,7 @@ function addNumber(acceptType, contentType, numberToAdd) {
addNumberReq.write(
contentType === "application/json"
? JSON.stringify(numberToAdd)
: cbor.encode(numberToAdd),
: cbor.encode(numberToAdd)
);

addNumberReq.on("response", (res) => {
Expand All @@ -253,7 +253,7 @@ function addNumber(acceptType, contentType, numberToAdd) {
if (contentType.includes("application/json")) {
console.log(
"Addition result (json): ",
JSON.parse(res.payload.toString()),
JSON.parse(res.payload.toString())
);
} else {
const decodedData = cbor.decode(res.payload);
Expand Down Expand Up @@ -287,7 +287,7 @@ function subtractNumber(acceptType, contentType, numberToSubtract) {
subtractNumberReq.write(
contentType === "application/json"
? JSON.stringify(numberToSubtract)
: cbor.encode(numberToSubtract),
: cbor.encode(numberToSubtract)
);

subtractNumberReq.on("response", (res) => {
Expand All @@ -297,7 +297,7 @@ function subtractNumber(acceptType, contentType, numberToSubtract) {
if (contentType.includes("application/json")) {
console.log(
"Subtraction result (json): ",
JSON.parse(res.payload.toString()),
JSON.parse(res.payload.toString())
);
} else {
const decodedData = cbor.decode(res.payload);
Expand Down Expand Up @@ -338,7 +338,7 @@ function observeUpdateEvent(acceptType) {
if (contentType.includes("application/json")) {
console.log(
"Observe update event (json): ",
JSON.parse(res.payload.toString()),
JSON.parse(res.payload.toString())
);
} else {
const decodedData = cbor.decode(res.payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ servient
.then(async (WoT) => {
try {
const td = await WoT.requestThingDescription(
"coap://localhost:5684/coap-calculator-content-negotiation",
"coap://localhost:5684/coap-calculator-content-negotiation"
);

const thing = await WoT.consume(td);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ servient
.then(async (WoT) => {
try {
const td = await WoT.requestThingDescription(
"coap://localhost:5683/coap-calculator-simple",
"coap://localhost:5683/coap-calculator-simple"
);

const thing = await WoT.consume(td);
Expand Down
Loading

0 comments on commit 41ed9c8

Please sign in to comment.