-
-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Add binary sensor platform to zwave_mqtt #35519
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
Merged
MartinHjelmare
merged 8 commits into
home-assistant:dev
from
marcelveldt:zwave_mqtt_binary_sensor
May 12, 2020
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fe5afdf
add binary sensor platform to zwave_mqtt
marcelveldt 9bdb80e
add tests for binary_sensor
marcelveldt 892d5c8
fix tests
marcelveldt 78c2fc0
device class is required value
marcelveldt d526f74
Update homeassistant/components/zwave_mqtt/binary_sensor.py
marcelveldt 6a1dca0
extend tests
marcelveldt a13c884
code optimize
marcelveldt 0f3c677
add test for enabling a legacy binary sensor
marcelveldt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| """Test Z-Wave Sensors.""" | ||
| from homeassistant.components.binary_sensor import ( | ||
| DEVICE_CLASS_MOTION, | ||
| DOMAIN as BINARY_SENSOR_DOMAIN, | ||
| ) | ||
| from homeassistant.components.zwave_mqtt.const import DOMAIN | ||
| from homeassistant.const import ATTR_DEVICE_CLASS | ||
|
|
||
| from .common import setup_zwave | ||
|
|
||
|
|
||
| async def test_binary_sensor(hass, generic_data, binary_sensor_msg): | ||
| """Test setting up config entry.""" | ||
| receive_msg = await setup_zwave(hass, fixture=generic_data) | ||
|
|
||
| # Test Legacy sensor (disabled by default) | ||
| registry = await hass.helpers.entity_registry.async_get_registry() | ||
| entity_id = "binary_sensor.trisensor_sensor" | ||
| state = hass.states.get(entity_id) | ||
| assert state is None | ||
| entry = registry.async_get(entity_id) | ||
| assert entry | ||
| assert entry.disabled | ||
| assert entry.disabled_by == "integration" | ||
|
|
||
| # Test enabling legacy entity | ||
| updated_entry = registry.async_update_entity( | ||
| entry.entity_id, **{"disabled_by": None} | ||
| ) | ||
| assert updated_entry != entry | ||
| assert updated_entry.disabled is False | ||
|
|
||
| # Test Sensor for Notification CC | ||
| state = hass.states.get("binary_sensor.trisensor_home_security_motion_detected") | ||
| assert state | ||
| assert state.state == "off" | ||
| assert state.attributes[ATTR_DEVICE_CLASS] == DEVICE_CLASS_MOTION | ||
|
|
||
| # Test incoming state change | ||
| receive_msg(binary_sensor_msg) | ||
| await hass.async_block_till_done() | ||
| state = hass.states.get("binary_sensor.trisensor_home_security_motion_detected") | ||
| assert state.state == "on" | ||
|
|
||
|
|
||
| async def test_sensor_enabled(hass, generic_data, binary_sensor_alt_msg): | ||
| """Test enabling a legacy binary_sensor.""" | ||
|
|
||
| registry = await hass.helpers.entity_registry.async_get_registry() | ||
|
|
||
| entry = registry.async_get_or_create( | ||
| BINARY_SENSOR_DOMAIN, | ||
| DOMAIN, | ||
| "1-37-625737744", | ||
| suggested_object_id="trisensor_sensor_instance_1_sensor", | ||
| disabled_by=None, | ||
| ) | ||
| assert entry.disabled is False | ||
|
|
||
| receive_msg = await setup_zwave(hass, fixture=generic_data) | ||
| receive_msg(binary_sensor_alt_msg) | ||
| await hass.async_block_till_done() | ||
|
|
||
| state = hass.states.get(entry.entity_id) | ||
| assert state is not None | ||
| assert state.state == "on" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| { | ||
| "topic": "OpenZWave/1/node/37/instance/1/commandclass/113/value/1970325463777300/", | ||
| "payload": { | ||
| "Label": "Home Security", | ||
| "Value": { | ||
| "List": [ | ||
| { | ||
| "Value": 0, | ||
| "Label": "Clear" | ||
| }, | ||
| { | ||
| "Value": 8, | ||
| "Label": "Motion Detected at Unknown Location" | ||
| } | ||
| ], | ||
| "Selected": "Motion Detected at Unknown Location", | ||
| "Selected_id": 8 | ||
| }, | ||
| "Units": "", | ||
| "Min": 0, | ||
| "Max": 0, | ||
| "Type": "List", | ||
| "Instance": 1, | ||
| "CommandClass": "COMMAND_CLASS_NOTIFICATION", | ||
| "Index": 7, | ||
| "Node": 37, | ||
| "Genre": "User", | ||
| "Help": "Home Security Alerts", | ||
| "ValueIDKey": 1970325463777300, | ||
| "ReadOnly": false, | ||
| "WriteOnly": false, | ||
| "ValueSet": false, | ||
| "ValuePolled": false, | ||
| "ChangeVerified": false, | ||
| "Event": "valueAdded", | ||
| "TimeStamp": 1579566891 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| { | ||
| "topic": "OpenZWave/1/node/37/instance/1/commandclass/48/value/625737744/", | ||
| "payload": { | ||
| "Label": "Sensor", | ||
| "Value": true, | ||
| "Units": "", | ||
| "Min": 0, | ||
| "Max": 0, | ||
| "Type": "Bool", | ||
| "Instance": 1, | ||
| "CommandClass": "COMMAND_CLASS_SENSOR_BINARY", | ||
| "Index": 0, | ||
| "Node": 37, | ||
| "Genre": "User", | ||
| "Help": "Binary Sensor State", | ||
| "ValueIDKey": 625737744, | ||
| "ReadOnly": false, | ||
| "WriteOnly": false, | ||
| "ValueSet": false, | ||
| "ValuePolled": false, | ||
| "ChangeVerified": false, | ||
| "Event": "valueAdded", | ||
| "TimeStamp": 1579566891 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.