Alexa smart home capabilities overriding one another - alexa

I have an Alexa project for smart home shades that include two range controllers, a brightness controller, and a toggle controller on each endpoint.
The two range controllers, toggle controller, and brightness controller all have different instances and friendlyNames.
When issuing commands to Alexa, anything containing a percentage is defaulting to the brightness controller regardless of how the command is phrased. If I fully remove the brightness controller and attempt to issue a rotation command (range controller), depending on the device, I get incredibly inconsistent results stating it doesn't know how to set the setting. Some devices will work around 90% at first and will then suddenly fail consistently. Other devices wont work at all. No device is consistently working.
If I reduce down to any one of the capabilities, it works nearly 100% of the time.
Has anyone else experienced this behavior and is there any solution?
Capability code:
export const ROTATE_CAPABILITY = {
type: "AlexaInterface",
interface: "Alexa.RangeController",
version: "3",
instance: "Blind.Rotate",
properties: {
supported: [{ name: "rangeValue" }],
proactivelyReported: false,
retrievable: true,
},
capabilityResources: {
friendlyNames: [
{
"#type": "text",
value: {
text: "Vane",
locale: "en-US"
}
},
{
"#type": "text",
value: {
text: "Tilt",
locale: "en-US"
}
},
{
"#type": "text",
value: {
text: "Angle",
locale: "en-US"
}
}
]
},
configuration: {
supportedRange: {
minimumValue: 0,
maximumValue: 100,
precision: 1,
},
unitOfMeasure: "Alexa.Unit.Percent"
}
}
export const BRIGHTNESS_CAPABILITY = {
type: "AlexaInterface",
interface: "Alexa.BrightnessController",
version: "3",
instance: "Blind.Brightness",
properties: {
supported: [
{
name: "brightness"
}
],
proactivelyReported: false,
retrievable: true
}
}
export const BRIGHTNESS_TOGGLE = {
type: "AlexaInterface",
interface: "Alexa.ToggleController",
instance: "Blind.Light",
version: "3",
properties: {
supported: [
{
name: "toggleState"
}
],
proactivelyReported: false,
retrievable: true,
nonControllable: false
},
capabilityResources: {
friendlyNames: [
{
"#type": "text",
value: {
text: "Shade Light",
locale: "en-US"
}
},
{
"#type": "text",
value: {
text: "Light",
locale: "en-US"
}
}
]
}
}
export const MAIN_CAPABILITY = {
type: "AlexaInterface",
interface: "Alexa.RangeController",
instance: "Blind.Lift",
version: "3",
properties: {
supported: [{
name: "rangeValue",
},],
proactivelyReported: false,
retrievable: true,
},
capabilityResources: {
friendlyNames: [
{
"#type": "text",
value: {
text: "Shade",
locale: "en-US"
}
}
],
},
configuration: {
supportedRange: {
minimumValue: 0,
maximumValue: 100,
precision: 1,
},
unitOfMeasure: "Alexa.Unit.Percent",
},
semantics: {
actionMappings: [{
"#type": "ActionsToDirective",
actions: ["Alexa.Actions.Close"],
directive: {
name: "SetRangeValue",
payload: {
rangeValue: 0,
},
},
},
{
"#type": "ActionsToDirective",
actions: ["Alexa.Actions.Open"],
directive: {
name: "SetRangeValue",
payload: {
rangeValue: 100,
},
},
},
{
"#type": "ActionsToDirective",
actions: ["Alexa.Actions.Lower"],
directive: {
name: "AdjustRangeValue",
payload: {
rangeValueDelta: -10,
rangeValueDeltaDefault: false,
},
},
},
{
"#type": "ActionsToDirective",
actions: ["Alexa.Actions.Raise"],
directive: {
name: "AdjustRangeValue",
payload: {
rangeValueDelta: 10,
rangeValueDeltaDefault: false,
},
},
},
],
stateMappings: [{
"#type": "StatesToValue",
states: ["Alexa.States.Closed"],
value: 0,
},
{
"#type": "StatesToRange",
states: ["Alexa.States.Open"],
range: {
minimumValue: 1,
maximumValue: 100,
},
},
],
},
}

Related

How to convert design token object to SCSS property using style dictionary?

I have the exact same issue as this thread: get scss from design tokens json file using style dictionary. The answer mentioned in this thread is great, but is there a way to specify some setting so that the style-dictionary automatically converts the style object to the way its mentioned in the answer in the mentioned thread?
I basically want to convert
"Display-2xl": {
"Regular": {
"value": {
"fontFamily": "{fontFamilies.inter.value}",
"fontWeight": "{fontWeights.inter-0.value}",
"fontSize": "$fontSize.10",
},
"type": "typography"
},
}
to
"Display-2xl": {
"Regular": {
"type": "typography",
"fontFamily": {
"value": "{fontFamilies.inter.value}"
},
"fontWeight": {
"value": "{fontWeights.inter-0.value}"
},
"fontSize": {
"value": "{fontSize.10}"
}
}
}
by adding some format / transform. How can I achieve this?
My config.json object:
const StyleDictionary = require("style-dictionary").extend({
source: ["./tokens.json"],
platforms: {
scss: {
transformGroup: "scss",
buildPath: "src/tokens/",
files: [
{
destination: "_colors.scss",
format: "scss/variables",
filter: {
type: "color",
},
},
{
destination: "_shadows.scss",
format: "scss/variables",
filter: {
type: "boxShadow",
},
},
{
destination: "_fontFamilies.scss",
format: "scss/variables",
filter: {
type: "fontFamilies",
},
},
{
destination: "_lineHeights.scss",
format: "scss/variables",
filter: {
type: "lineHeights",
},
},
{
destination: "_fontWeights.scss",
format: "scss/variables",
filter: {
type: "fontWeights",
},
},
{
destination: "_fontSizes.scss",
format: "scss/variables",
filter: {
type: "fontSizes",
},
},
{
destination: "_letterSpacing.scss",
format: "scss/variables",
filter: {
type: "letterSpacing",
},
},
{
destination: "_paragraphSpacing.scss",
format: "scss/variables",
filter: {
type: "paragraphSpacing",
},
},
{
destination: "_typography.scss",
format: "scss/variables",
filter: {
type: "typography",
},
},
{
destination: "_textCase.scss",
format: "scss/variables",
filter: {
type: "textCase",
},
},
{
destination: "_textDecoration.scss",
format: "scss/variables",
filter: {
type: "textDecoration",
},
},
],
},
},
});
StyleDictionary.buildAllPlatforms();
The question makes in my opinion no sense, the solution is mentioned on the linked site already:
"Display-2xl": {
" ": { // Has to be a space. This comment also will break json
value: "PARENT VALUE"
},
"Regular": {
"type": "typography",
"fontFamily": {
"value": "{fontFamilies.inter.value}"
},
"fontWeight": {
"value": "{fontWeights.inter-0.value}"
},
"fontSize": {
"value": "{fontSize.10}"
}
}
}
Beside that the json represents a configuration and has to be created but a conversion from one json configuration format to another json configuration format is probably not part of the framework, concerning this the question might be just a bit misleading.
Nevertheless, both configurations can be used and should have the same result.

Remove/delete json value (multiple array)

I want to remove 'Software 3' in the array. I'm quite new with json data and I do not know what is the correct way to do it. I have tried the unset method but its not working. Can anyone show me the example. I already search the solution but most of it not using multiple array.
json data:
"system_info": {
"hardware": {
"model": "PowerEdge R710",
"serialno": "FG6MC2S",
"warranty": {
"warranty_start_date": "2022-03-14",
"warranty_end_date": "2025-03-14"
}
},
"operating_env": {
"os": "PowerEdge R710",
"os_version": "FG6MC2S"
},
"software_installed": [
{
"name": "Software 1",
"version": "4.5"
},
{
"name": "Software 2",
"version": "5.5"
},
{
"name": "Software 3",
"version": "5.5"
}
]},
Using javascript
const data = {
system_info: {
hardware: {
model: 'PowerEdge R710',
serialno: 'FG6MC2S',
warranty: {
warranty_start_date: '2022-03-14',
warranty_end_date: '2025-03-14',
},
},
operating_env: {
os: 'PowerEdge R710',
os_version: 'FG6MC2S',
},
software_installed: [
{
name: 'Software 1',
version: '4.5',
},
{
name: 'Software 2',
version: '5.5',
},
{
name: 'Software 3',
version: '5.5',
},
],
},
};
const { system_info: { hardware, operating_env, software_installed } } = data;
const newData = {
system_info: {
hardware,
operating_env,
software_installed: software_installed.filter(s => s.name !== 'Software 3')
}
}
console.log(newData);
Using python. I will assume that this data lives in data.json
remove_script.py
import json
# Opening JSON file
with open('data.json') as json_file:
data = json.load(json_file)
# Remove software 3
data['system_info'].update(
{"software_installed": data['system_info']['software_installed'][:2]})
print(data)
# write to another file
with open("output.json", "w") as write_file:
json.dump(data, write_file, indent=4)
printed output
>>> {'system_info': {'hardware': {'model': 'PowerEdge R710', 'serialno': 'FG6MC2S', 'warranty': {'warranty_start_date': '2022-03-14', 'warranty_end_date': '2025-03-14'}}, 'operating_env': {'os': 'PowerEdge R710', 'os_version': 'FG6MC2S'}, 'software_installed': [{'name': 'Software 1', 'version': '4.5'}, {'name': 'Software 2', 'version': '5.5'}]}}
output.json
{
"system_info": {
"hardware": {
"model": "PowerEdge R710",
"serialno": "FG6MC2S",
"warranty": {
"warranty_start_date": "2022-03-14",
"warranty_end_date": "2025-03-14"
}
},
"operating_env": {
"os": "PowerEdge R710",
"os_version": "FG6MC2S"
},
"software_installed": [
{
"name": "Software 1",
"version": "4.5"
},
{
"name": "Software 2",
"version": "5.5"
}
]
}
}

How to create nested array in realm without key(React Native)

{
"a": [
[
{
"_id": "57e55b64016c3551c025abc1",
"title": "Main Campus"
},
{
"_id": "5810e2e27064497f74ad4874",
"title": "Ahm Campus"
},
{
"_id": "5d5d2633a1d0680620ac3cce",
"title": "Baroda"
},
{
"_id": "5d5d3af3a1d0680620ac3ef8",
"title": "India"
}
],
[
{
"_id": "57e55b64016c3551c025abc1",
"title": "Main Campus"
},
{
"_id": "5810e2e27064497f74ad4874",
"title": "Ahm Campus"
},
{
"_id": "5d5d2633a1d0680620ac3cce",
"title": "Baroda"
},
{
"_id": "5d5d3af3a1d0680620ac3ef8",
"title": "India"
}
]
]
}
How to create the schema in the realm(React native) for this type of JSON object. I tried all possible ways but did not found any specific solution. Basically, it is a nested array where the second array does not have any specific key(I tried with key it works fine but I want to do it without adding key).
You can use something like:
const ParentSchema = {
name: "parent",
properties: {
key: "string",
values: "Value[]"
}
};
const ValueSchema = {
name: "Value",
embedded: true,
properties: {
_id: "string",
title: "string"
}
};
You can insert objects like:
realm.write(() => {
realm.create("Parent", { key: "a", values: [
{ _id: "57e55b64016c3551c025abc1", title: "Main Campus" },
{ _id: "5810e2e27064497f74ad4874", title: "Ahm Campus" }
]
});
});
Documentation: https://docs.mongodb.com/realm/node/data-model
As of now there is no way to insert direct value in Realm database without key so for now we need to modify data and then we can store in following schema.
const ParentSchema = {
name: "parent",
properties: {
a: "level[]"
}
};
const level = {
name: 'level',
properties: {
level: 'sites[]'
}
}
const sites = {
name: 'sites',
properties: {
sites: 'site[]'
}
}
const site = {
name: 'site',
properties: {
title: 'string?',
_id: 'string?',
version: 'int?',
}
}
Data modification need to done like following.
var a = {
level: []
}
data.a.map((Site, index) => {
const sites = []
Site.map((s) => { sites.push(s)})
a.level.push({sites})
})

how to push data in inside array mongodb?

i am trying to push array in document array my collection is
{
"_id": "58eed81af6f8e3788de703f9",
"first_name": "abc",
"vehicles": {
"exhibit": "18",
"title": "Motor Velicle Information for Donald French",
"details": [
{
"year": "",
"make_model": "",
"registered_owner": "",
"license_number": "",
"date_of_purchase": "",
"purchase_price": ""
}
]
}
}
so what i want is to push data in details for that i had try like this
Licensee.update({"_id":"58eed81af6f8e3788de703f9"},{
$push:{
"vehicles.details":data
}
},function(err,data){
if(!err)
{
console.log('data',data);
}
else
{
console.log('err',err);
}
});
and for this i create one schema i don't know is right or not
var licSchema = new SimpleSchema({
"_id":{
type:String,
label:"_id",
optional: false,
},
"vehicles.details.year": {
type: String,
label: "year",
optional: true,
},
"vehicles.details.make_model": {
type: String,
label: "make_model",
optional: true,
}
});
where is my fault please give me solution .
Error Uncaught Error: After filtering out keys not in the schema, your modifier is now empty
You can try this. AddToSet should be the right way.
const schema = new SimpleSchema({
"vehicles.details.$.year": {
type: String,
label: "year",
optional: true,
},
"vehicles.details.$.make_model": {
type: String,
label: "make_model",
optional: true,
}
});
Licensee.update({"_id":"58eed81af6f8e3788de703f9"},{
$addToSet:{
"vehicles.details": data
}
});

Highcharts using Directives in AngularJS

I am new to Angular and just getting used to how everything fits together. I want to display a chart through a directive. This chart will be static data so will neither be dynamically loaded nor updated, it is taken from a JSON.
I have referenced here but the main difference is that I am not loading Highcharts in the view. I am loading it globally in the .js file from my bower_components directory. This is my code:
.js
/* global Highcharts */
angular.module("fusoDataLoggerChart", [])
.controller("fusoDataLoggerChartController", ["$http", "$scope", function($http, $scope) {
"use strict";
$scope.data = {
"activities": [
{},
{},
{
"title": "Engine speed",
"type": "DATA_LOGGER",
"result": {
"Engine speed": {
"data": [
{
"timestamp": 0,
"value": {
"type": "QUANTITY",
"unit": "rpm",
"value": 900
}
},
{
"timestamp": 1000,
"value": {
"type": "QUANTITY",
"unit": "rpm",
"value": 1000
}
},
{
"timestamp": 2000,
"value": {
"type": "QUANTITY",
"unit": "rpm",
"value": 2000
}
}
]
},
"Accelerator pedal position": {
"data": [
{
"timestamp": 0,
"value": {
"type": "QUANTITY",
"unit": "%",
"value": 0
}
},
{
"timestamp": 1000,
"value": {
"type": "QUANTITY",
"unit": "%",
"value": 10.6
}
},
{
"timestamp": 2000,
"value": {
"type": "QUANTITY",
"unit": "%",
"value": 11
}
}
]
}
}
}
]
}
}])
.directive("fusoDataLoggerChart", function() {
"use strict";
return {
scope: {},
restrict: 'E',
link: function(scope) {
scope.dataLoggerData = scope.data["activities"][2]["result"];
scope.timestamps = getData()[0];
scope.engineSpeeds = getData()[1];
scope.pedalPositions = getData()[2];
var chart = new Highcharts.Chart({
chart: {
type: 'line',
animation: false,
renderTo: "DataLoggerChartContainer",
zoomType: 'x'
},
credits: {
enabled: false
},
title: {
text: null
},
xAxis: {
type: "linear",
title: {
text: "Timestamp"
},
min: 0,
categories: scope.timestamps
},
yAxis: [{ //Engine Speed
title: {
text: 'Engine Speed'
},
labels: {
format: '{value} RPM'
},
opposite: true
}, { //Accelerator Pedal Position
title: {
text: 'Accelerator Pedal Position'
},
labels: {
format: '{value} %'
},
min: 0,
max: 100,
// FIXME: 'allowDecimal' may not work
allowDecimal: true
}],
series: [{
name: 'Engine Speed',
type: 'spline',
yAxis: 1,
tooltip: {
valueSuffix: ' RPM'
},
data: scope.engineSpeeds
}, {
name: 'Accelerator Pedal Position',
type: 'spline',
yAxis: 2,
tooltip: {
valueSuffix: ' %'
},
data: scope.pedalPositions
}]
});
function getData() {
var timestamps = [],
engineSpeeds = [],
pedalPositions = [];
var engineSpeedData = scope.dataLoggerData["Engine Speed"]["data"],
pedalPosData = scope.dataLoggerData["Accelerator Pedal Position"]["data"];
for (var i in engineSpeedData) {
timestamps.push(engineSpeedData[i].timestamp);
}
for (var j in engineSpeedData) {
engineSpeeds.push(engineSpeedData[j].value.value);
}
for (var k in pedalPosData) {
pedalPositions.push(pedalPosData[k].value.value);
}
return [timestamps, engineSpeeds, pedalPositions];
}
}
}
});
HTML
<fuso-data-logger-chart>
<div id="DataLoggerChartContainer"></div>
</fuso-data-logger-chart>
When I go to where the chart is to be rendered, nothing is shown (and only the HTML code set manually is displayed with nothing inside when I check in DevTools).
N.B: I realize I do not need the controller yet but it is there as in future the JSON will be got from a rest call from within the controller
Any help appreciated.
This isn't a full answer to your question, but I noticed a way you can make your HTML directive a little cleaner so that you could instead use this format:
<fuso-data-logger-chart></fuso-data-logger-chart>
You don't need the <div id="DataLoggerChartContainer">. You can embed that in the directive definition as a template:
.directive("fusoDataLoggerChart", function() {
"use strict";
return {
scope: {},
restrict: 'E',
transclude: true,
template: '<div id="DataLoggerChartContainer"></div>'
link: function(scope) {
... your other code ...
}
}
});
I have figured out the problem. There were multiple errors but I'll leave this here so maybe someone else can find it useful:
Highcharts and my FusoDataLoggerChart.js were not loaded into index.html (<script src="modules/readVehicleData/FusoDataLoggerChart.js"></script>) meaning that they couldn't be seen by Angular.
In my directive, I was trying to access the local scope (scope.data) in the link() function instead of trying to access the parent scope in the controller where the data is set. To access the parent scope, scope.$parent.data worked for me (N.B: was only 'data' for me as that's the value I set)

Resources