Add ZwaveStringSensor to OZW integration (#38676)

* Add ZwaveStringSensor to OZW integration

* Remove unnecessary new line

* Set enabled default to false for ZwaveStringSensor

* Add missing decorator for property

* Add a test for ZwaveStringSensor

* Also test state of ZWaveStringSensor

* Remove entity type check
This commit is contained in:
Fritiof Hedman authored and GitHub committed 2020-08-23 15:16:26 +02:00
1 parent 62b1f23328
commit 961f36c679
4 files changed
+54

No files matched your search

+22
View File
@@ -36,6 +36,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
elif isinstance(value.primary.value, dict):
sensor = ZWaveListSensor(value)
elif isinstance(value.primary.value, str):
sensor = ZWaveStringSensor(value)
else:
_LOGGER.warning("Sensor not implemented for value %s", value.primary.label)
return
@@ -93,6 +96,25 @@ class ZwaveSensorBase(ZWaveDeviceEntity):
return True
class ZWaveStringSensor(ZwaveSensorBase):
"""Representation of a Z-Wave sensor."""
@property
def state(self):
"""Return state of the sensor."""
return self.values.primary.value
@property
def unit_of_measurement(self):
"""Return unit of measurement the value is expressed in."""
return self.values.primary.units
@property
def entity_registry_enabled_default(self):
"""Return if the entity should be enabled when first added to the entity registry."""
return False
class ZWaveNumericSensor(ZwaveSensorBase):
"""Representation of a Z-Wave sensor."""
+6
View File
@@ -87,6 +87,12 @@ def lock_data_fixture():
return load_fixture("ozw/lock_network_dump.csv")
@pytest.fixture(name="string_sensor_data", scope="session")
def string_sensor_fixture():
"""Load string sensor MQTT data and return it."""
return load_fixture("ozw/sensor_string_value_network_dump.csv")
@pytest.fixture(name="sent_messages")
def sent_messages_fixture():
"""Fixture to capture sent messages."""
+21
View File
@@ -74,3 +74,24 @@ async def test_sensor_enabled(hass, generic_data, sensor_msg):
assert state is not None
assert state.state == "0"
assert state.attributes["label"] == "Clear"
async def test_string_sensor(hass, string_sensor_data):
"""Test so the returned type is a string sensor."""
registry = await hass.helpers.entity_registry.async_get_registry()
entry = registry.async_get_or_create(
SENSOR_DOMAIN,
DOMAIN,
"1-49-73464969749610519",
suggested_object_id="id_150_z_wave_module_user_code",
disabled_by=None,
)
await setup_ozw(hass, fixture=string_sensor_data)
await hass.async_block_till_done()
state = hass.states.get(entry.entity_id)
assert state is not None
assert state.state == "asdfgh"
@@ -0,0 +1,5 @@
OpenZWave/1/status/,{ "OpenZWave_Version": "1.6.1240", "OZWDaemon_Version": "0.1.170", "QTOpenZWave_Version": "1.2.0", "QT_Version": "5.12.9", "Status": "driverAllNodesQueried", "TimeStamp": 1598022319, "ManufacturerSpecificDBReady": true, "homeID": 3389163831, "getControllerNodeId": 1, "getSUCNodeId": 1, "isPrimaryController": true, "isBridgeController": false, "hasExtendedTXStatistics": true, "getControllerLibraryVersion": "Z-Wave 3.95", "getControllerLibraryType": "Static Controller", "getControllerPath": "/dev/zwave"}
OpenZWave/1/node/49/,{ "NodeID": 49, "NodeQueryStage": "Complete", "isListening": false, "isFlirs": true, "isBeaming": true, "isRouting": true, "isSecurityv1": false, "isZWavePlus": true, "isNIFRecieved": true, "isAwake": true, "isFailed": false, "MetaData": { "OZWInfoURL": "http://www.openzwave.com/device-database/0373:0001:0003", "ZWAProductURL": "https://products.z-wavealliance.org/products/2780/", "ProductPic": "images/idlock/idlock150.png", "Description": "A module enabling your ID Lock digital door lock to a Z-Wave Plus enabled digital door Lock. The module is compatible with ID Lock 101 and ID Lock 150. It enables your ID Lock to operate in a Z-Wave network with numerous access control funtions and notifications.", "ProductManualURL": "https://idlock.no/wp-content/uploads/2019/08/IDLock150_ZWave_UserManual_v3.02.pdf", "ProductPageURL": "https://idlock.no/z-wave/", "InclusionHelp": "Inclusion – (Puts your device in inclusion mode) • Push and hold key button until all LEDs on touch panel activates (with ID Lock in an unlocked state). • Release button. • Enter Master PIN followed by * on touch panel. • Press digit \"2\" for settings followed by * on touch panel. • Press digit “5” on touch panel. Inclusion mode starts immediately. LED indicator below logo signals this by flashing blue.", "ExclusionHelp": "Exclusion – (Puts your device in exclusion mode) • Push and hold key button until all LEDs on touch panel activates (with ID Lock in an unlocked state). • Release button. • Enter Master PIN followed by * on touch panel. • Press digit \"2\" for settings followed by * on touch panel. • Press digit “5” on touch panel. Exclusion mode starts immediately. LED indicator below logo signals this by flashing blue.", "ResetHelp": "Device reset – (This will reset RF interface module to factory default settings) Warning: Please do only proceed with the following reset procedure, if primary network controller is missing or otherwise inoperable. RESET Z-WAVE MODULE: • Push and hold key button until all LEDs on touch panel activates (with ID Lock in an unlocked state). • Release button. • Enter Master PIN followed by * on keypad. • Press digit \"2\" for settings followed by * on keypad. • Press digit “0” on keypad. If the Z-wave module is not included in a Z-wave network the door lock will also return to factory settings when following the above procedure. FACTORY RESET DOOR LOCK FIRMWARE: • Push and hold inside lock/unlock button while inserting the fourth battery. • Receive reset sound. • Release button. • Receive confirmation sound.", "WakeupHelp": "Activate by touching the touch panel with finger(s), the palm of the hand on the outside unit or by pushing the key button on the inside unit.", "ProductSupportURL": "https://idlock.no/kundesenter/", "Frequency": "CEPT (Europe)", "Name": "ID Lock 150 Z-Wave module", "ProductPicBase64": "iVBORw0KGgoAAAANSUhEUgAAAMgAAACaCAIAAABjfJA1AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAgAElEQVR4nOy8Wa9lR3YmtlYMezrzcMe8U85MMjmzWMUqUlWqQaUqSQV1q9GS5Uaj3XADNgw/+MkwDFt68pP/gNsG/OiG293VakHqdqnmSUUWyeSUyUzmdOfp3DPueUfEWn44ySyKUhs2bMMwrLjAAfa95+yIG/tb3/rWEAeZGf6vDWZGxH/X5f+Nb/4/tYy/nff/lXkfDyQiAEDE+Qcev/4fnOZvx/+fx/8OyP5mDBHRaDSy1v4/vLC/Hf/fHs1mMwzDObbmQHqMM/XJ9zEzM+/vH/x3//SfPnzwEMgRESJadEop4YhRAqJzDgCBQQjBzPObMeCc6vjju5NzwAwAQkgUKIVktohAjqx1iMAAAqVzpJR6vCAGkgIB2DkGEADAwICMACgEMAIDIAgUACAEOjLzNSihiIjIoWBmFkKSk8wshJjfGREdGCYSQgiQQiAzExMzC4HIQkqJiM4Z5xwzC6kQ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EREdS5QIgIBKKSWVdZaApRQSpYRHvlaitNYCIjBIpZy1zISIKNAYEygPWQDynHKcc845JZW1pLVm5kZUR0SBoizLsiwQhed7SZoKRHYYhkGe50islRZSlFVJREpJwWyMAUAByvf92XSKkhHRkSuMJVtJXzpL1laATCScI8cExAjITAAoBCqlXGWZaP5ItNZERI4QwBEh4By1jmmuJRQTzsmbEVkAAjmaW8Vjj0OOwDmHIISQJBw5IkZmCw4BEKVCxcCVMQ5YCvSUR+SIWAI6IkJnGYUQUmjnnBLine truncated
OpenZWave/1/node/49/instance/1/,{ "Instance": 1, "TimeStamp": 1598022021}
OpenZWave/1/node/49/instance/1/commandclass/113/,{ "Instance": 1, "CommandClassId": 113, "CommandClass": "COMMAND_CLASS_NOTIFICATION", "CommandClassVersion": 4, "TimeStamp": 1598022021}
OpenZWave/1/node/49/instance/1/commandclass/113/value/73464969749610519/,{ "Label": "User Code", "Value": "asdfgh", "Units": "", "ValueSet": false, "ValuePolled": false, "ChangeVerified": false, "Min": 0, "Max": 0, "Type": "String", "Instance": 1, "CommandClass": "COMMAND_CLASS_NOTIFICATION", "Index": 261, "Node": 49, "Genre": "User", "Help": "User Code that was used", "ValueIDKey": 73464969749610519, "ReadOnly": true, "WriteOnly": false, "Event": "valueAdded", "TimeStamp": 1598022021}