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:
parent
62b1f23328
commit
961f36c679
4 changed files with 54 additions and 0 deletions
|
@ -36,6 +36,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
elif isinstance(value.primary.value, dict):
|
elif isinstance(value.primary.value, dict):
|
||||||
sensor = ZWaveListSensor(value)
|
sensor = ZWaveListSensor(value)
|
||||||
|
|
||||||
|
elif isinstance(value.primary.value, str):
|
||||||
|
sensor = ZWaveStringSensor(value)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
_LOGGER.warning("Sensor not implemented for value %s", value.primary.label)
|
_LOGGER.warning("Sensor not implemented for value %s", value.primary.label)
|
||||||
return
|
return
|
||||||
|
@ -93,6 +96,25 @@ class ZwaveSensorBase(ZWaveDeviceEntity):
|
||||||
return True
|
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):
|
class ZWaveNumericSensor(ZwaveSensorBase):
|
||||||
"""Representation of a Z-Wave sensor."""
|
"""Representation of a Z-Wave sensor."""
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,12 @@ def lock_data_fixture():
|
||||||
return load_fixture("ozw/lock_network_dump.csv")
|
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")
|
@pytest.fixture(name="sent_messages")
|
||||||
def sent_messages_fixture():
|
def sent_messages_fixture():
|
||||||
"""Fixture to capture sent messages."""
|
"""Fixture to capture sent messages."""
|
||||||
|
|
|
@ -74,3 +74,24 @@ async def test_sensor_enabled(hass, generic_data, sensor_msg):
|
||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == "0"
|
assert state.state == "0"
|
||||||
assert state.attributes["label"] == "Clear"
|
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"
|
||||||
|
|
5
tests/fixtures/ozw/sensor_string_value_network_dump.csv
vendored
Normal file
5
tests/fixtures/ozw/sensor_string_value_network_dump.csv
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue