Skip to content

Commit

Permalink
Merge pull request #22 from sultur/smartthings
Browse files Browse the repository at this point in the history
Smartthings updated
  • Loading branch information
johannkarlsson authored Jun 22, 2022
2 parents f95ee7f + e47e773 commit 62a2767
Show file tree
Hide file tree
Showing 8 changed files with 24,478 additions and 4 deletions.
1 change: 1 addition & 0 deletions queries/iot_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def help_text(lemma: str) -> str:
(
"Tengu miðstöðina",
"Tengdu ljósin"
"Tengdu hátalarann"
)
)
)
Expand Down
1 change: 1 addition & 0 deletions queries/iot_hue.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ def sentence(state: QueryStateDict, result: Result) -> None:

# Fetch relevant data from the device_data table to perform an action on the lights
device_data = cast(Optional[DeviceData], q.client_data(smartdevice_type))
print("location :", q.location)
print("device data :", device_data)

selected_light: Optional[str] = None
Expand Down
32 changes: 32 additions & 0 deletions queries/js/IoT_Embla/Smart_Things/fuse_search_st.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Fuzzy search function that returns an object in the form of {result: (Object), score: (Number)}
* @param {String} query - The search term
* @param {Object} data - The data to search
*/
function smartThingsFuzzySearch(query, data) {
// Restructure data to be searchable by name
var newData = Object.keys(data).map(function (key) {
return { ID: key, info: data[key] };
});
// Fuzzy search for the query term (returns an array of objects)
var fuse = new Fuse(newData, {
keys: ["info", "info.name"],
includeScore: true,
shouldSort: true,
threshold: 0.5,
});
let searchResult = fuse.search(query);

let resultObject = new Object();
console.log("result: ", searchResult);
if (searchResult[0] === undefined) {
console.log("no match found");
return null;
} else {
// Structure the return object to be in the form of {result: (Object), score: (Number)}
resultObject.result = searchResult[0].item;
resultObject.score = searchResult[0].score;
console.log("resultObject :", resultObject);
return resultObject;
}
}
4 changes: 4 additions & 0 deletions queries/js/IoT_Embla/Smart_Things/st.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ <h1>SmartThings Test</h1>
<button class="brightnessUp" onClick="raiseBrightness()">Brightness up</button>
<button class="brightnessDown" onClick="lowerBrightness()">Brightness down</button>
</div>
<u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
<InstanceID>ui4</InstanceID>
<Speed>string</Speed>
</u:Play>
</main>
</body>
</html>
Expand Down
15 changes: 13 additions & 2 deletions queries/js/IoT_Embla/Smart_Things/st.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const AUTH_TOKEN = "Bearer 85dabaad-10de-4f74-94a7-0dee4685982e";
const AUTH_TOKEN = "";

function turnOnLight() {
var myHeaders = new Headers();
Expand Down Expand Up @@ -126,7 +126,17 @@ function lowerBrightness() {
.catch((error) => console.log("error", error));
}

function smartThingsWrapper(device, capability, command, arguments = null) {
function smartThingsWrapper(
query,
device,
capability,
command,
arguments = null
) {

targetObject = smartThingsFuzzySearch(query)


var myHeaders = new Headers();
myHeaders.append("Authorization", AUTH_TOKEN);
myHeaders.append("Content-Type", "application/json");
Expand Down Expand Up @@ -159,3 +169,4 @@ function smartThingsWrapper(device, capability, command, arguments = null) {
.then((result) => console.log(result))
.catch((error) => console.log("error", error));
}

3 changes: 1 addition & 2 deletions queries/js/IoT_Embla/Smart_Things/st_connecthub.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ async function storeDevice(data, ipAddress) {
}

// bearer token 64780d2b-b763-433d-95ca-3eaaf5e10642
async function connectHub(clientID, ipAddress) {
async function connectHub(clientID, ipAddress, bearerToken) {
console.log("connect hub");
let bearerToken = "64780d2b-b763-433d-95ca-3eaaf5e10642";

try {
const data = {
Expand Down
Loading

0 comments on commit 62a2767

Please sign in to comment.