Skip to content

Added more devices and types to onewire#9404

Merged
balloob merged 4 commits into
home-assistant:devfrom
tcastberg:dev
Sep 14, 2017
Merged

Added more devices and types to onewire#9404
balloob merged 4 commits into
home-assistant:devfrom
tcastberg:dev

Conversation

@tcastberg
Copy link
Copy Markdown
Contributor

@tcastberg tcastberg commented Sep 12, 2017

Description:

Added support for humidity and pressure in 1-wire devices. Also added support for a couple of new (old) devices.

This update changes the names of the sensors from "<sensor_name>" to "<sensor_name> <Sensor_type>"
Example: Kitchen -> Kitchen Temperature.
In the database this looks like: sensor.kitchen -> sensor.kitchen_temperature.
This was a necessary change as devices with multiple sensors would be given additional _n suffixes in the database that would be not be persistent per sensor across restarts of HA.
If you wish to maintain a single line of record in the database this can be achieved by the following recipe.

Connect to your database using the instructions from https://home-assistant.io/docs/backend/database/
Check the names of sensors:
SELECT entity_id, COUNT(*) as count FROM states GROUP BY entity_id ORDER BY count DESC LIMIT 10;
Alter the names of sensors using the following examples:
UPDATE states SET entity_id='sensor.<sensor_name>_temperature' WHERE entity_id LIKE 'sensor.<sensor_name>%' AND attributes LIKE '%\u00b0C%';
UPDATE states SET entity_id='sensor.<sensor_name>_pressure' WHERE entity_id LIKE 'sensor.<sensor_name>%' AND attributes LIKE '%mb%';
UPDATE states SET entity_id='sensor.<sensor_name>_humidity' WHERE entity_id LIKE 'sensor.<sensor_name>%' AND attributes LIKE '%%%' ESCAPE '';
Remember to replace <sensor_name> with the actual name of the sensor as seen in the SELECT query.

Checklist:

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.

device_files = []
devs = []
device_names = {}
if 'names' in config.keys():
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to add .keys() to test if a key exists.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will update.

def __init__(self, name, device_file, stype):
"""Initialize the sensor."""
self._name = name
self._name = name+' '+stype
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This means that it is no longer possible for people to override the name. We should only append the type if no name was given.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The solution in the earlier code led to some issues with assigning the correct values to the right type. Should be ok to just remove this change now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, and removing the change should also lead to removing breaking change status I guess.

def update(self):
"""Get the latest data from the device."""
temp = -99
value = -99
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Default value should be None

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, I just went with what was there. Will update.

Copy link
Copy Markdown
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.

Nice work! Just a couple of comments.

Since it is changing the default names, it will also influence how entity ids are generated. This makes this a breaking change. Please add a paragraph in your PR description how users are impacted and how to upgrade.

@tcastberg
Copy link
Copy Markdown
Contributor Author

As the name change is not really necessary, I will remove the change.

@tcastberg
Copy link
Copy Markdown
Contributor Author

Ok, it looks like it does not work the way I thought. I figured that HA would put values of the same _type always in the same bucket regardless if the names are the same. It does not appear to be the case. I now get millibar values in the temperature chart under history.
What is the appropriate way to solve this?

@tcastberg
Copy link
Copy Markdown
Contributor Author

Added the change back and updated the description. Does it look ok?

Copy link
Copy Markdown
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.

🐬 thanks! Nice work!

@balloob balloob merged commit 5b453ca into home-assistant:dev Sep 14, 2017
@balloob
Copy link
Copy Markdown
Member

balloob commented Sep 14, 2017

Please make sure to submit a PR with updated documentation

@tcastberg
Copy link
Copy Markdown
Contributor Author

@balloob
Copy link
Copy Markdown
Member

balloob commented Sep 14, 2017

That is the current documentation, it however does not contain the addition that you just made.

Please make sure that when you open a PR you do it against the next branch.

@balloob balloob mentioned this pull request Sep 22, 2017
@home-assistant home-assistant locked and limited conversation to collaborators Mar 3, 2018
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.

3 participants