How to create a config file for a homebridge accessory - json

I have installed a plugin to control my Samsung TV (https://github.com/xeenon/homebridge-samsung-tv) via my Homebridge server, however the developer did not provide a config-sample.json, hence why I am trying to make my own. I am entirely new to coding so please tell me what I am doing wrong.
This is the part of my config file for that accessory as of now (I will add the ip adress and mac adress later).
{
"bridge": {
"name": "Homebridge",
"username": "",
"port": 4318,
"pin": "031-45-154"
},
"accessories": [{
"accessory": "samsungTv",
"name": "samsungTvAccessory",
"ip_address": "",
"macAddress": "",
"polling": "true",
"pollingInterval": "1"
}]
}
When I am trying to start Homebridge I get the error
TypeError: Cannot read property 'forEach' of undefined
at new SamsungTvAccessory (usr/local/lib/node_modules/homebridge-samsung-tv-controller/index.js:76:10
If I however change the config file to
{
"bridge": {
"name": "Homebridge",
"username": "",
"port": 4318,
"pin": "031-45-154"
},
"accessories": [{
"accessory": "samsungTv",
"name": "samsungTvAccessory",
"ip_address": "",
"macAddress": "",
"polling": "true",
"pollingInterval": "1",
"enabledInputs": "true"
}]
}
where I added
"enabledInputs": "true"
i get the error
TypeError: config.enabledInputs.forEach is not a function
at new SamsungTvAccessory (usr/local/lib/node_modules/homebridge-samsung-tv-controller/index.js:76:10
I would really appreciate any help!

Did you try valid JSON ? Would tell you are missing brackets around, also from first lines of source it looks like. It should work like this
objectVar = {
"accessory": "samsungTv",
"name": "samsungTvAccessory",
"ip_adress": "",
"macAddress": "",
"polling": "true",
"pollingInterval": "1"
}
Or like this in case it you are using string somewhere: "{\"accessory\":\"samsungTv\",\"name\":\"samsungTvAccessory\",\"ip_adress\":\"\",\"macAddress\":\"\",\"polling\":\"true\",\"pollingInterval\":\"1\"}"
And then there are methods JSON.stringify(objectVar [, null, indent]) or JSON.parse(string) to convert to string or back. Stringify has also optional parameters - first is a replacer function and second indent if you want it people friendly formatted.

Related

Anyone know how to add paramters to Faker functions on mockapi.io?

I'm exploring API mocking tool and this one seems to be the bee's knees. Even with out figuring this out, I'm still probably going to use it for my needs.
But there's a thing that bugs me. You can mock the response you want using Faker.js in their JSON editor like so:
{
"username": "$internet.userName",
"balance": "$finance.amount"
}
This will result in a response that looks like:
[
{
"username": "Leilani46",
"balance": "116.96",
"userid": "1"
},
{
"username": "Ellie.Stehr26",
"balance": "15.37",
"userid": "2"
},
{
"username": "Gilda60",
"balance": "677.77",
"userid": "3"
},
... etc
]
According to the Faker docs you can add parameters to the methods to control the output a little. For example finance.amount(4,10) will give you a number between 4 and 10.
I haven't found a way to get this to work, these have been my attempts:
{
"username": "$internet.userName",
"balance": "$finance.amount(4,10)"
}
{
"username": "$internet.userName",
"balance": "$finance.amount 4 10"
}
...etc
It always just results in the literal string
[
{
"username": "Leilani46",
"balance": "116.96",
"userid": "1"
},
{
"username": "Ellie.Stehr26",
"balance": "$finance.amount(4,10)",
"userid": "2"
},
{
"username": "Gilda60",
"balance": "$finance.amount(4,10)",
"userid": "3"
},
... etc
]
I've reached out to their contact email, but there's no better place to tell me I'm asking too much of this world than StackOverflow.
Beuller?
For completion, they reached back out to me and confirmed that what I want to do isn't available, yet.

Why is JSON being detected as empty?

So I have a JSON file I got from Postman which is returning as an empty object. This is how I'm reading it.
import regscooter from './json_files/reginald_griffin_scooter.json'
const scoot = regscooter;
const CustomerPage = () => {...}
reginald_griffin_scooter.json
{
"success": true,
"result": {
"id": "hhhhhhhhhh",
"model": "V1 Scooter",
"name": "hhhhhhhhhh",
"status": "active",
"availabilityStatus": "not-available",
"availabilityTrackingOn": true,
"serial": "hhhhhhhhhhhh",
"createdByUser": "hhhhhhhhK",
"createdByUsername": "hhhhhhhh",
"subAssets": [
"F0lOjWBAnG"
],
"parts": [
"hhhhhhhh"
],
"assignedCustomers": [
"hhhhhhhhh"
],
"createdAt": "2019-12-03T21:47:26.218Z",
"updatedAt": "2020-06-26T22:05:54.526Z",
"customFieldsAsset": [
{
"id": "hhhhhhh",
"name": "MAC",
"value": "hhhhhhhh",
"asset": "hhhhhhhhhh",
"user": "hhhhhhhhh",
"createdAt": "2019-12-03T21:47:26.342Z",
"updatedAt": "2019-12-11T16:29:24.732Z"
},
{
"id": "hhhhhhhh",
"name": "IMEI",
"value": "hhhhhhh",
"asset": "hhhhhhh",
"user": "hhhhhhhhhh",
"createdAt": "2019-12-03T21:47:26.342Z",
"updatedAt": "2019-12-11T16:29:24.834Z"
},
{
"id": "hhhhhhhhh",
"name": "Key Number",
"value": "NA",
"asset": "hhhhhhhhh",
"user": "hhhhhhhhhhh",
"createdAt": "2019-12-03T21:47:26.342Z",
"updatedAt": "2019-12-11T16:29:24.911Z"
}
]
}
}
The error is that "const scoot" is being shown as an empty object {}. I made sure to save a ton of times everywhere. I am able to read through the imported JSON file in other variables in similar ways, so I don't know why I can't parse this one. I just want to access the JSON object inside this. Also I omitted some information with hhhhh because of confidentiality.
EDIT: The code works, but it still has a red line beneath result when I do:
const scoot = regscooter.result.id;
It would be much more effective if you will provide an example in codesandbox or so.
However at first look it might be a parser issue ( maybe you are using Webpack with missing configuration for parsing files with json extension ), meaning we need more information to provide you with a full answer ( maybe solution ? ).
Have you tried to do the next:
const scoot = require('./json_files/reginald_griffin_scooter.json');

How to read data from nested JSON structure in protractor

Below is my code and I want to extract data under "specs" part like description, status etc. however I'm getting undefined when I capture the data and print it in the console. I have tried
let web = JSON.parse(jsondata);
let TestSuite = web["suite1"]["description"]
and this is providing data in console however, when I use this,
let id = web["suite1"]["specs"]["id"]
its gives undefined. Please help!
{
"suite1": {
"id": "suite1",
"description": "Login",
"fullName": "Login",
"failedExpectations": [],
"status": "finished",
"specs": [
{
"id": "spec0",
"description": "Should able to login into the Distribution management Webpage",
"fullName": "Login Should able to login into the Distribution management Webpage",
"failedExpectations": [
{
"matcherName": "",
"message": "",
"stack": "",
"passed": false,
"expected": "",
"actual": ""
}
],
"passedExpectations": [],
"pendingReason": "",
"started": "2018-09-06T06:57:42.740Z",
"status": "failed",
"duration": "7 secs",
"stopped": "2018-09-06T06:57:49.255Z",
"browserLogs": []
}
]
} }
JSON.parse(JSON.stringify(json)).suite1.specs[0].id
specs contains an array of objects. First, you need to get the object from the array and then get a value of the object.
Try this:
let id = web["suite1"]["specs"][0]["id"]
OR
let id = web.suite1.specs[0].id
Hope this will work.
When you do ["suite1"]["specs"], you select array. You need an index, which is the 0-th one in this case.
You can check that by typing Object.prototype.toString.call( data["suite1"]["specs"]).
You can try with:
data["suite1"]["specs"][0]["id"]
Or use the object property notation
data["suite1"]["specs"][0].id

Getting the value of an image field in Plone 3.x with FSS

I'm trying to migrate an old Plone 3.3 site that uses
FileSystemStorage using Mikko's Simple JSON export script.
Everything runs fine, except for the absence of a value on the image fields, which are returned as empty strings (''):
[
...
{
"allowDiscussion": false,
"contributors": [],
"creation_date": "2009-11-04T15:15:36-02:00",
"creators": [
"johndoe"
],
"description": "",
"effectiveDate": null,
"excludeFromNav": false,
"expirationDate": null,
"id": "banner_vertical.jpg",
"image": "",
"language": "",
"location": "",
"modification_date": "2009-11-04T15:15:37-02:00",
"portal_type": "Image",
"relatedItems": [],
"rights": "",
"subject": [],
"title": "Banner vertical",
"urlLegend": "http://"
},
...
]
Any hint?
(iw.fss version used is 2.8.0rc5).
FSS was not known or used by the site for which the script has been made.
You might want to retrofit convert() and other methods to support your use case.

Returning data from parsed xml to JSON

I am attempting to display some data from JSON that contains parsed XML, in an angular application, and I am stuck.
I can extract the other fields like so {{object.articleId}}. How can I extract child data from the content object? For example, if I need to extract the "default-locale"? I would like to be able to do {{object.content.default-locale}} but this is not working obviously.
[
{
"articleId": "393800",
"classNameId": 0,
"classPK": 0,
"companyId": 10157,
"content": "{\"root\":{\"default-locale\":\"en_US\",\"dynamic-element\":[{\"index\":0,\"index-type\":\"keyword\",\"dynamic-content\":{\"content\":\"[\\\"General News\\\"]\",\"language-id\":\"en_US\"},\"name\":\"Top_News\",\"type\":\"radio\"},{\"index\":0,\"index-type\":\"keyword\",\"dynamic-content\":{\"content\":\"_All\",\"language-id\":\"en_US\"},\"name\":\"Location\",\"type\":\"list\"},{\"index\":0,\"index-type\":\"keyword\",\"dynamic-content\":{\"content\":\"CTC\",\"language-id\":\"en_US\"},\"name\":\"Business_Unit\",\"type\":\"list\"},{\"index\":0,\"index-type\":\"keyword\",\"dynamic-content\":{\"content\":\"hfhfahfcaf;\",\"language-id\":\"en_US\"},\"name\":\"Subtitle\",\"type\":\"text\"},{\"index\":0,\"index-type\":\"keyword\",\"dynamic-content\":{\"content\":\"dhfhfowejfwkfpw\",\"language-id\":\"en_US\"},\"name\":\"Intro_Text\",\"type\":\"text\"},{\"index\":0,\"index-type\":\"keyword\",\"dynamic-content\":{\"content\":\"1430697600000\",\"language-id\":\"en_US\"},\"name\":\"News_Date\",\"type\":\"ddm-date\"},{\"index\":0,\"index-type\":\"\",\"dynamic-content\":{\"content\":\"/image/journal/article?img_id=393803&t=1430750130449\",\"id\":393803,\"language-id\":\"en_US\"},\"name\":\"News_Image\",\"type\":\"image\"},{\"index\":0,\"index-type\":\"keyword\",\"dynamic-content\":{\"content\":\"flkdsjfldsjffa\",\"language-id\":\"en_US\"},\"name\":\"Freeform\",\"type\":\"text_area\"},{\"index\":0,\"index-type\":\"keyword\",\"dynamic-content\":{\"content\":\"test\",\"language-id\":\"en_US\"},\"name\":\"News_Tag_1\",\"type\":\"text\"},{\"index\":0,\"index-type\":\"keyword\",\"dynamic-content\":{\"language-id\":\"en_US\"},\"name\":\"News_Tag_2\",\"type\":\"text\"},{\"index\":0,\"index-type\":\"keyword\",\"dynamic-content\":{\"language-id\":\"en_US\"},\"name\":\"News_Tag_3\",\"type\":\"text\"}],\"available-locales\":\"en_US\"}}",
"createDate": 1430750130000,
"description": "",
"descriptionCurrentValue": "",
"displayDate": 1430749860000,
"expirationDate": 1430836418000,
"folderId": 236650,
"groupId": 10184,
"id": 393801,
"indexable": true,
"layoutUuid": "",
"modifiedDate": 1430836418000,
"resourcePrimKey": 393802,
"reviewDate": null,
"smallImage": false,
"smallImageId": 393804,
"smallImageURL": "",
"status": 3,
"statusByUserId": 10439,
"statusByUserName": "Admin",
"statusDate": 1430836418000,
"structureId": "236652",
"templateId": "236654",
"title": "<?xml version='1.0' encoding='UTF-8'?><root available-locales=\"en_US\" default-locale=\"en_US\"><Title language-id=\"en_US\">Test</Title></root>",
"titleCurrentValue": "Test",
"treePath": "/236650/",
"type": "general",
"urlTitle": "test",
"userId": 10439,
"userName": "Admin",
"uuid": "f06c946e-6efb-4a28-81f3-2a78e1a20814",
"version": 1.0
}
]
Thanks in advance for your assistance
content is actually a json string.
You need to loop over that data when you receive it and set:
object.content = angular.fromJson(object.content);
Perhaps this could be also cleaned up at source if you control the api that is sending it