Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Add binary_sensor support #53

Merged
merged 11 commits into from
Oct 26, 2016
Merged

Add binary_sensor support #53

merged 11 commits into from
Oct 26, 2016

Conversation

rcloran
Copy link
Contributor

@rcloran rcloran commented Oct 12, 2016

No description provided.

@mention-bot
Copy link

@rcloran, thanks for your PR! By analyzing the history of the files in this pull request, we identified @robbiet480, @maddox and @shmuelzon to be potential reviewers.

@rcloran
Copy link
Contributor Author

rcloran commented Oct 12, 2016

This might not be enough to generally support more types of motion sensors, but I figure that those that need extra functionality (door is actually an example, and I should make it more complete) can extend the binary sensor

this.entity_id = data.entity_id
if (data.attributes && data.attributes.friendly_name) {
this.name = data.attributes.friendly_name
}else{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nitpicking) } else { plz

@@ -186,6 +188,12 @@ HomeAssistantPlatform.prototype = {
accessory = new HomeAssistantSwitch(that.log, entity, that, 'input_boolean')
}else if (entity_type == 'fan'){
accessory = new HomeAssistantFan(that.log, entity, that)
}else if (entity_type == 'binary_sensor'){
if (entity.attributes && entity.attributes.sensor_class == 'opening') {
accessory = new HomeAssistantBinarySensor(that.log, entity, that, Service.Door, Characteristic.CurrentPosition, 100, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like for Service.Door these characteristics are required:

  • Characteristic.CurrentPosition
  • Characteristic.PositionState
  • Characteristic.TargetPosition

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it would be good to allow users to specify whether this is a door or window with a customize parameter (something like homebridge_opening_binary_sensor_type). If door, use Service.Door and if window use Service.Window. Otherwise you're going to get a lot of false positives for those that have sensors on things other than doors.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could cheat though and not listen to me entirely and use the (what seems to be much simpler) Service.ContactSensor

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing out some other super easy to implement binary_sensors for extra credit:

Oh also, opening could be used with Service.ContactSensor.

@robbiet480
Copy link
Member

@rcloran Instead of adding a bunch of }else if (entity.attributes && entity.attributes.sensor_class == 'motion') conditionals can we just check for the existence of the sensor_class attribute and then have a switch case inside the 1 conditional?

@robbiet480
Copy link
Member

@rcloran FYI I'm around on Gitter if you wanted to chat more about this

@rcloran
Copy link
Contributor Author

rcloran commented Oct 13, 2016

I don't have any of the other sensors to test with, so I'll need to do a little research, but I'm happy to add them in here.

@@ -27,6 +27,8 @@ Here's a list of the devices that are currently exposed:
* **Rollershutter** - exposed as a garage door
* **Fan** - on/off/speed
* **Input boolean** - on/off
* **Door** - open/close state exposed
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how you'd like this updated.

Service.ContactSensor is convenient, but it is semantically wrong, so we get
some bad UI - for example, Siri cannot answer "Is the Front Door open?"
opening_type = Service.Window;
}else{
opening_type = Service.Door;
}
Copy link
Contributor Author

@rcloran rcloran Oct 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do some heuristics around here - if friendly name or entity id contains the string window, make it a window, etc. If it gets any fancier than this, I'd be inclined to put that in HomeAssistantOpening's constructor. What do you think?

Copy link
Collaborator

@maddox maddox Oct 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think since you're looking at the ha sensor and conditionally setting characteristics here already, this is probably the place to do this as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was actually in the sensor, heh.I think the runtime decisions of characteristics should probably be in binary_sensor.js.

@rcloran rcloran changed the title Add binary_sensor support with doors and motion sensors Add binary_sensor support Oct 13, 2016
@rcloran
Copy link
Contributor Author

rcloran commented Oct 13, 2016

Do you think Service.ContactSensor and sensor_class connectivity match?

@@ -22,7 +22,7 @@
"url": "http://github.com/home-assistant/homebridge-homeassistant/issues"
},
"engines": {
"node": ">=0.12.0",
"node": ">=6.0.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try not to change the minimum required version of node in feature pull requests like this. We're going to bump it soon, but it will be on it's own pull request. There's nothing in this pull that really requires this anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that I don't need to bump the version to use the feature (class keyword) that I need to achieve the goal (inheritance). @robbiet480 said this would be OK, which is why I went ahead with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a later commit, I reduced this to ">=4.3.2", which is the version that introduced the class keyword. It's also the minimum version that's required by the homebridge package, so it doesn't actually represent anything different in what users will need to have set up.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm at node -v 4.3.7 but getting errors when running your modifications... Probably something simple I've overlooked and any help appreciated:

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mod

this.offValue = Characteristic.SmokeDetected.SMOKE_NOT_DETECTED
break
default:
return null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no good. null from the constructor is ignored.

@robbiet480
Copy link
Member

@maddox Can you also look at this one too. Thx.

@maddox
Copy link
Collaborator

maddox commented Oct 26, 2016

🚢

rcloran and others added 2 commits October 26, 2016 12:09
* Add support for thermometers

* Handle onEvent

* Address review comments

 - Use UTF-8 encoded degree symbol instead of escape
 - Remove climate support
 - Remove testing stuff

* Change to a more generic sensor class

* Update README

* jshint suggested changes
@robbiet480 robbiet480 merged commit d445afa into home-assistant:master Oct 26, 2016
@robbiet480 robbiet480 mentioned this pull request Oct 26, 2016
15 tasks
robbiet480 pushed a commit that referenced this pull request Oct 29, 2016
* Add uuid_base to all accessories

Currently, homebridge uses the accessory type and display name to generate the
UUID. That means that if two devices have the same display name in the house,
we will crash on startup. It also means that renaming a device will have all
of its HomeKit configuration (like which room it is in) lost.

This change will break many peoples' setups - devices will be put in the
default room, and they will need to re-organize them.

* Add sensor support (#52)

* Add support for thermometers

* Handle onEvent

* Address review comments

 - Use UTF-8 encoded degree symbol instead of escape
 - Remove climate support
 - Remove testing stuff

* Change to a more generic sensor class

* Update README

* jshint suggested changes

* Add binary_sensor support (#53)

* Add binary_sensor support with doors and motion sensors

* Change from Service.Door to Service.ContactSensor

* Formatting changes

* Move back to Service.Door, add Service.Window

Service.ContactSensor is convenient, but it is semantically wrong, so we get
some bad UI - for example, Siri cannot answer "Is the Front Door open?"

* Add some more trivial binary sensors

* Correct node requirement

* Move specializations into constructor

* Fix null return from constructor by making it a factory function

* jshint suggested changes

* Add sensor support (#52)

* Add support for thermometers

* Handle onEvent

* Address review comments

 - Use UTF-8 encoded degree symbol instead of escape
 - Remove climate support
 - Remove testing stuff

* Change to a more generic sensor class

* Update README

* jshint suggested changes

* Update binary_sensor and sensor to use uuid_base
@robbiet480
Copy link
Member

@rcloran Going back for a minute now that I actually have tried this out...

You said "Service.ContactSensor is convenient, but it is semantically wrong, so we get
some bad UI - for example, Siri cannot answer "Is the Front Door open?"

I agree that that's annoying but at the same time I don't know if presenting binary_sensors as supporting state changes from HomeKit is a good idea either. I'm surprised you can't ask Siri if a contact sensor is open/closed since it is HomeKit defined...

@rcloran
Copy link
Contributor Author

rcloran commented Oct 30, 2016

Hrm - there may have been something else wrong while I was trying it out, I
guess. Unfortunately I'm traveling this week, so won't be able to test any
actual interactions until next Sunday.
On Sun, Oct 30, 2016 at 15:26, Robbie Trencheny notifications@github.com
wrote:

@rcloran https://github.com/rcloran Going back for a minute now that I
actually have tried this out...

You said "Service.ContactSensor is convenient, but it is semantically
wrong, so we get
some bad UI - for example, Siri cannot answer "Is the Front Door open?"

I agree that that's annoying but at the same time I don't know if
presenting binary_sensors as supporting state changes from HomeKit is a
good idea either. I'm surprised you can't ask Siri if a contact sensor is
open/closed since it is HomeKit defined...


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#53 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA-P5S0XZr_M6O4oQHyr6A73JvEppV1tks5q5Rl6gaJpZM4KVSZ_
.

@robbiet480
Copy link
Member

@rcloran I changed it to be ContactSensor and Siri continued to work so I pushed the change to master.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants