Skip to content
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

Thermostat Occupancy Sensor Integration #37

Merged
merged 4 commits into from
Nov 13, 2018
Merged

Thermostat Occupancy Sensor Integration #37

merged 4 commits into from
Nov 13, 2018

Conversation

jhkolb
Copy link
Contributor

@jhkolb jhkolb commented Nov 3, 2018

These changes allow us to collect occupancy data from occupancy sensors that are associated with Pelican thermostats and report data through the Pelican API.

This has been tested on thermostats bound to Enlighted occupancy sensors.

@@ -14,6 +14,7 @@ import (

const TSTAT_PO_DF = "2.1.1.0"
const DR_PO_DF = "2.1.1.9"
const OCCUPANCY_PO_DF = "2.1.2.1"
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'm just using the existing i.xbos.occupancy interface. Let me know if I should create a different interface to use here.

Copy link
Member

Choose a reason for hiding this comment

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

LGTM!

@@ -37,6 +37,8 @@ type Pelican struct {
target string
timezone *time.Location
req *gorequest.SuperAgent
drReq *gorequest.SuperAgent
Copy link
Contributor Author

Choose a reason for hiding this comment

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

SuperAgent instances aren't thread safe. I was routinely getting panics during my testing because we now have multiple goroutines for each Pelican thermostat simultaneously issuing requests.

Here, the Pelican structs now have one SuperAgent instance for each of their associated goroutines: The main status goroutine, the DR event goroutine, and the new occupancy data goroutine.

I'm open to suggestions if we want to take a different approach.

Copy link
Member

Choose a reason for hiding this comment

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

The alternative I guess would be a whole locking wrapper around the SuperAgent, which doesn't strike me as worth it. This looks great!

@jhkolb jhkolb requested a review from gtfierro November 3, 2018 19:48
@gtfierro
Copy link
Member

gtfierro commented Nov 7, 2018

Thanks for pulling this together @jhkolb

Couple questions:

  • in your testing, did you find that the pelicans sometimes have more than one auxiliary occupancy sensor?
  • are there other kinds of sensors that the pelicans are hooked up with besides occupancy?

@jhkolb
Copy link
Contributor Author

jhkolb commented Nov 7, 2018

No, all of the Pelicans I saw had just one sensor associated with the each thermostat.

I'm not sure how common these auxiliary sensors are. I haven't seen this anywhere besides the single deployment that motivated this PR in the first place. So while it's possible other kinds of sensors are out there, I haven't seen them.

Also, it's worth noting that the sensors report both a Name and Type field. If the Pelican API uses a consistent schema, then hopefully this logic will work with any sensor that reports its type as occupancy, not just Enlighted sensors in particular.

occupancy, err := currentPelican.GetOccupancy()
if err != nil {
fmt.Printf("Failed to read thermostat occupancy: %s\n", err)
done <- true
Copy link
Member

Choose a reason for hiding this comment

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

Can you change this so that the error is printed out, but the driver doesn't stop? Until we're more sure of the failure cases of the auxiliary sensors, I think it might make for a more robust deployment if the driver continues to run and try to access the sensors. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, that makes sense. Just pushed an update to address this.

@gtfierro gtfierro merged commit f8bce91 into master Nov 13, 2018
@gtfierro
Copy link
Member

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants