-
-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix switch accessory & add support for Smart IR (wnykq) #115
Conversation
bimusiek
commented
Nov 22, 2022
- Fix bug introduced in Update naming logic of Dimmer, Switch, Valve. #114
- Add support for temperature & humidity sensor (Smart IR)
The error in JSON.parse comes from this response:
This opens up the way to support Infrared devices I guess? I will try to make it work soon as I have one light that I would love to be able to control. How do you feel about adding config option to configure infra devices as this seems like a really custom-tailored list of commands. Or maybe I dont know the inner workings of Tuya platform. |
Thanks for the PR, unfortunately the IR device returns wrong specification format, completely different with others, I have contact the cloud development peoples, due to the history reason they refuse to fix. I prefer to let the plugin convert to the same format before we use. I will confirm how to convert these days. I prefer add config to override per-device or per-product info, instead of just create a device in the config, so we can keep the device list data source is only from one place (from API). The user can add the IR subdevice in the tuya app, then the IR subdevice can both be used in app and plugin. If it should be implemented as the switch accessory or specific accessory depends on the specific IR data the command sent. In your case the brightness command is "Brightness+" "Brightness-" much like an "action", not "Brightness 60%" "Brightness 70%" as a "state". Can we open this PR for a while and let me check the spec convertion things? Thanks for your contribution! |
So just to clarify things, Smart IR reports temp and humidity with proper schema. It behaves like thermometer so I think its fine to make it be discovered as one. Other ir devices could be parsed as each action is a switch but I could prepare separate PR for that. |
src/device/TuyaDeviceManager.ts
Outdated
if (schemas[code]) { | ||
continue; | ||
} | ||
const type = rawType.charAt(0).toUpperCase() + rawType.slice(1).toLowerCase(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My IR device spec is like this:
path = /v1.0/devices/6c66dfa384bdc2bbb2yqql/specifications
data = {
"result": {
"category": "infrared_ac",
"functions": [
{
"code": "F",
"type": "ENUM",
"values": "{\"min\":0,\"max\":3,\"scale\":0,\"step\":1,\"type\":\"Integer\"}"
},
{
"code": "M",
"type": "ENUM",
"values": "{\"min\":0,\"max\":4,\"scale\":0,\"step\":1,\"type\":\"Integer\"}"
},
{
"code": "PowerOff",
"type": "STRING",
"values": "PowerOff"
},
{
"code": "PowerOn",
"type": "STRING",
"values": "PowerOn"
},
{
"code": "T",
"type": "ENUM",
"values": "{\"min\":16,\"max\":30,\"scale\":0,\"step\":1,\"type\":\"Integer\"}"
}
],
"status": [
{
"code": "wind",
"type": "ENUM",
"values": "{\"min\":0,\"max\":3,\"scale\":0,\"step\":1,\"type\":\"Integer\"}"
},
{
"code": "mode",
"type": "ENUM",
"values": "{\"min\":0,\"max\":4,\"scale\":0,\"step\":1,\"type\":\"Integer\"}"
},
{
"code": "power",
"type": "BOOLEAN",
"values": "{}"
},
{
"code": "temp",
"type": "ENUM",
"values": "{\"min\":16,\"max\":30,\"scale\":0,\"step\":1,\"type\":\"Integer\"}"
}
]
},
"success": true,
"t": 1667552909972,
"tid": "3fde5b005c2011ed9f2b629ef151a136"
}
The ENUM
actually is Integer
, the STRING
is like a Enum
type with 1 range, BOOLEAN
is same as Boolean
. They have to be some dirty code to convert this :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explaining, I will revert this code for now and we can discuss it further what is the best approach here
@@ -256,10 +256,10 @@ export class TuyaPlatform implements DynamicPlatformPlugin { | |||
this.log.info(`Got home_id=${home_id}, name=${name}`); | |||
if (this.options.homeWhitelist) { | |||
if (this.options.homeWhitelist.includes(home_id)) { | |||
this.log.info(`Found home_id=${home_id} in whitelist; including devices from this home.`); | |||
homeIDList.push(home_id); | |||
this.log.info(`Found home_id=${home_id} in whitelist; including devices from this home.`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've noticed this and I don't know why npm run lint
not return warnings for me and github actions, but ./node_modules/.bin/eslint src/**/**.ts --max-warnings=0
works. Do you know why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my case, using eslint directly also works:
❯ ./node_modules/.bin/eslint src/**/**.ts --max-warnings=0
❯ echo $?
0
Do you have some additional global config specified? Or some prettier rules if you are using VSCode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldnt it be
eslint src/**/*.ts --max-warnings=0
? with one asterisk before .ts
Besides this, no clue why it wouldnt return errors in actions.
src/device/TuyaDeviceManager.ts
Outdated
@@ -107,7 +110,11 @@ export default class TuyaDeviceManager extends EventEmitter { | |||
} | |||
let property: TuyaDeviceSchemaProperty; | |||
try { | |||
property = JSON.parse(values); | |||
if (type === TuyaDeviceSchemaType.String) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
STRING
value is a string, but String
value is a json object string like {\"maxlen\":255}
defines the max length.
Sorry I forget to submit the review, It was left as pending state and you can't see. Now it is visible. |
Here's some informations: IR additional API, if IoT Core not satisfied your requirements: A Tuya plugin focused on IR devices: Thanks again, I was intend to do this after December, but I'm a little bit busy and don't have enough time to develop and test recently. |
Hey @0x5e please re-check 👍 |
Thanks again! @bimusiek |