-
Notifications
You must be signed in to change notification settings - Fork 10
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
Use config.json for configuring sensors. #31
Use config.json for configuring sensors. #31
Conversation
Updated PR to fix the case where the |
Using the below config.json, I can't get the filter to work. Sensors which are not listed in the config still show up, e.g. "Thermometer 1", even though the tdtool output for that particular sensor is
PS. Do I really need to clear out the accessories and persist folders, change the MAC and pin of Homebridge in config.json in order to test this? Is there a better way? |
@pkempe strange, that should not be the case. With this PR, unnamed sensors should be named "Sensor 14", etc, and nothing related to "Termomether xx" should be visible. I'm not 100% sure on the need to clear things out of homekit though. Can you please paste the log you see when starting up homekit with this PR merged? If this doesn't work, please try installing from https://github.com/jannylund/homebridge-telldus-tdtool/tree/develop (Which is similar, but with all PR's merged) |
@pkempe I confirmed there is no need to clear out anything. Just removing one of these instances from your config and restarting homebridge is enough. You should see something like this in startup:
|
Here's there log:
|
Considering the above, it seems I have not correctly installed the PR properly. Isn't |
@pkempe yes, I confirmed that it works if I do it that way. (however I run If you still have issues, maybe try to make a clean clone of this repo. (or simply clone my fork and use the develop branch). |
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 very much like the implementation, although I have a few nit picks.
@@ -32,28 +32,34 @@ class TelldusTDToolPlatform { | |||
this.log = log | |||
this.config = config | |||
this.homebridge = homebridge | |||
this.senzors = config["sensors"] || []; |
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.
Why not sensors
? I'm also not sure why this would need to be a instance variable, when this.devices
is not.
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.
devices
are coming from the output of tdtool, since they are configured in telldus.conf
. The only reason to use senzors
instead of sensors
is to avoid confusion with the local variable sensors
used in the else
clause.
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'd really like to avoid this, as sensors can be derived from the config object. Let's keep state to a minimum and rely on the config object instead.
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.
Fixed.
sensors.forEach((current, index) => {sensors[index].name = `Thermometer ${current.id}`}) | ||
return devices.concat(sensors) | ||
}) | ||
if (this.senzors.length > 0) { |
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'd rather rely on this.config.sensors
.
return devices.concat(sensors) | ||
}) | ||
if (this.senzors.length > 0) { | ||
this.log(foundOfTypeString('sensor', this.senzors.length, 'config.json')) |
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.
As this is user input, we should verify that the fields supplied are 'name'
(optional), 'type'
and 'id'
and nothing else.
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.
As of the other PR, it's also possible to provide maxAge
.
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 saw that, and if you do not wish to address all these constraints in this PR it's fine, we just need to track it in another issue.
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.
Let's make it another PR as it otherwise needs changes in the other PR as well.
} | ||
}) | ||
return devices.concat(this.senzors); | ||
} else { |
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.
The else clause here seems superfluous, but it's up to you whether you want to keep it or not.
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.
The ideal case to me would be if we could print the path where config.json
was read as well, but that might be a bit over the top for an initial implementation.
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.
The else
clause is simply there for backwards compatibility, but I agree, it could be removed if you are ok with dropping autoconfigured sensors?
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.
Sorry for the confusion, that's not what I meant. I just meant that
if (this.senzors.length > {
// ...
}
return ...
provides the same functionality as
if (this.senzors.length > {
// ...
} else {
return ...
}
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.
Ok, now I understand. Yeah, that could be done, but in this case I think it's more readable to keep the else
.
@@ -215,8 +215,12 @@ class TelldusHygrometer extends TelldusAccessory { | |||
getHumidity(callback, context) { | |||
this.log('Checking humidity...') | |||
TDtool.sensor(this.id, this.log).then(s => { | |||
this.log(`Found humidity ${s.humidity}%`) | |||
callback(null, parseFloat(s.humidity)) | |||
if (s == undefined) { |
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'd like to go with ===
as standard.
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.
Fixed.
@@ -266,8 +270,12 @@ class TelldusThermometer extends TelldusAccessory { | |||
getTemperature(callback, context) { | |||
this.log(`Checking temperature...`) | |||
TDtool.sensor(this.id, this.log).then(s => { | |||
this.log(`Found temperature ${s.temperature}`) | |||
callback(null, parseFloat(s.temperature)) | |||
if (s == undefined) { |
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'd like to go with ===
as standard.
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.
Fixed.
@@ -313,8 +321,12 @@ class TelldusThermometerHygrometer extends TelldusThermometer { | |||
getHumidity(callback, context) { | |||
this.log('Checking humidity...') | |||
TDtool.sensor(this.id, this.log).then(s => { | |||
this.log(`Found humidity ${s.humidity}%`) | |||
callback(null, parseFloat(s.humidity)) | |||
if (s == undefined) { |
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'd like to go with ===
as standard.
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.
Fixed.
I think this one is done now. Please merge it if you agree, and I'll rebase #30 |
Thanks for submitting this, looks like a good implementation and a good interface to me. Tracking the progress on feedback to config fields on #35. |
This PR adds the functionality to use config file as documented in #30
sensors
array or adding an empty array, it will work as before (Except the removed feature override sensortype, since that is done in config file)sensors
array brings the following features:config.json
ensures it's always the same (correct) name.config.json
allows reconfiguration of falsetemperaturehumidity
astemperature
.Each sensor need to have two mandatory members,
id
(to identify it uniquely) andmodel
(since we don't know that at this stage).