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

Add Eight sleep component #7275

Merged
merged 7 commits into from May 2, 2017
Merged

Add Eight sleep component #7275

merged 7 commits into from May 2, 2017

Conversation

mezz64
Copy link
Contributor

@mezz64 mezz64 commented Apr 24, 2017

Description:

Implementation of a component to fetch data from Eight Sleep covers and mattresses.

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#2499

Example entry for configuration.yaml (if applicable):

eight_sleep:
    username: "user@email.com"
    password: "password"
    partner: true

Checklist:

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

@mention-bot
Copy link

@mezz64, thanks for your PR! By analyzing the history of the files in this pull request, we identified @balloob, @fabaff and @pvizeli to be potential reviewers.

return self._state

@property
def state(self):
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this. This is taken care of by the BinarySensor entity.

async_add_devices(all_sensors, True)


class EightHeatSensor(EightSleepHeatEntity):
Copy link
Member

Choose a reason for hiding this comment

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

You need to always also inherit from the component abstract bcase class that you're a platform a for, in this case BinarySensorDevice

return STATE_ON if self.is_on else STATE_OFF

@property
def unit_of_measurement(self):
Copy link
Member

Choose a reason for hiding this comment

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

Remove this and it will default to None.

hass.data[DATA_EIGHT] = eight

# Authenticate, build sensors
yield from eight.start()
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to validate that the auth is correct here and return False if it's incorrect ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I'll add it into the library and update accordingly.


if 'current' in self._sensor_root:
state_attr[ATTR_RESP_RATE] = round(self._attr['resp_rate'], 2)
state_attr[ATTR_HEART_RATE] = round(self._attr['heart_rate'], 2)
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it make more sense for a lot of these things to be separate sensors?

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 can go that route if you think it makes more sense. My intention was to make the data available and let the user template out whichever values they were interested in since they are only updated when a sleep session is active. Right now we're at 8 total sensors for both left/right sides of the bed, if I split out the active session values we'd be adding another 10. It just seemed like data overload to me.

Copy link
Member

Choose a reason for hiding this comment

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

You're right, that is a lot of entities . But maybe still split out the temperature sensors? Those are always nice to have. Those also don't have to be shared per side of the bed.

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've broken out the bed temps, room temp, and sleep stage. I think those would be the most useful.

state_attr[ATTR_RESP_RATE] = round(self._attr['resp_rate'], 2)
state_attr[ATTR_HEART_RATE] = round(self._attr['heart_rate'], 2)
state_attr[ATTR_SLEEP_STAGE] = self._attr['stage']
state_attr[ATTR_ROOM_TEMP] = room_temp
Copy link
Member

Choose a reason for hiding this comment

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

Especially these would be great to break out into their own entities.

Copy link
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

Beautiful! 🐬

@balloob balloob merged commit 752a4b9 into home-assistant:dev May 2, 2017
@balloob balloob mentioned this pull request May 5, 2017
@mezz64 mezz64 deleted the eight_sleep branch May 22, 2017 14:46
@home-assistant home-assistant locked and limited conversation to collaborators Sep 4, 2017
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