* Add support for config_flow Add support for switches Add support for binary sensors * Add config flow strings * Update .coveragerc * black-formatting * fixes for isort and flake * fixes for pylint * fixes for isort * fixes for isort * fixes for config_flow * Add devices to Device Registry * Updated comments * fixes for flake8 * Updated comments * Updated comments * Implement async_unload_entry * remove binary_sensor and switch implementation (will move to new PR) * Update .coveragerc Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Update .coveragerc * Review config flow to store the configuration type * Add config_flow tests * Move CONF_NAMES to constants * Fix isort * Tweak to onewire logger * Tweak to onewire logger for sensor * Reset _LOGGER variable * Normalise header * Normalise header * Update to use references in config flow translations * Improve test coverage * fixes for isort * Update async_unload_entry * Update common strings * Update imports * Move connect attempt to executor * Update common strings * Remove OWFS from config_flow * Prevent duplicate config entries * Fix isort * Fix flake8 * Fix tests following removal of OWFS implementation * Fix flake8 * Adjust config from yaml to config-flow, and add ability to specify sysbus directory * Ajust unique_id for config entries * Fix test_config_flow * Fix invalid merge * Convert yaml to config_entry * Update sysbus tests * Tweaks to yaml import process, and add OWFS warning * Enable migration of OWFS platform config to config_entry * update the existing corresponding config entry on OWFS conversion * Remove CONFIG_SCHEMA * Move data_schema to constants * Remove log message * Remove duplicate warning * Update already_configured to use already_configured_device constant * Schedule get_entities on the executor * Update duplicate entry check for OWServer * Review TryCatch * Schedule os.path.isdir on the executor * rename owhost/owport * Update checks for empty * Fix incorrect patch * Move config_flow validation methods to new OneWireHub * Fix typo and pre-commit * Cleanup try/else * patch async_setup/async_setup_entry * cleanup implicit exit point * Fix invalid patch * cleanup implicit exit point * cleanup implicit exit point Co-authored-by: Chris Talkington <chris@talkingtontech.com>
121 lines
4.0 KiB
Python
121 lines
4.0 KiB
Python
"""Tests for 1-Wire devices connected on SysBus."""
|
|
from unittest.mock import patch
|
|
|
|
from pi1wire import InvalidCRCException, UnsupportResponseException
|
|
import pytest
|
|
|
|
from homeassistant.components.onewire.const import DEFAULT_SYSBUS_MOUNT_DIR, DOMAIN
|
|
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
|
from homeassistant.const import TEMP_CELSIUS
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
from tests.common import mock_registry
|
|
|
|
MOCK_CONFIG = {
|
|
"sensor": {
|
|
"platform": DOMAIN,
|
|
"mount_dir": DEFAULT_SYSBUS_MOUNT_DIR,
|
|
"names": {
|
|
"10-111111111111": "My DS18B20",
|
|
},
|
|
}
|
|
}
|
|
|
|
MOCK_DEVICE_SENSORS = {
|
|
"00-111111111111": {"sensors": []},
|
|
"10-111111111111": {
|
|
"sensors": [
|
|
{
|
|
"entity_id": "sensor.my_ds18b20_temperature",
|
|
"unique_id": "/sys/bus/w1/devices/10-111111111111/w1_slave",
|
|
"injected_value": 25.123,
|
|
"result": "25.1",
|
|
"unit": TEMP_CELSIUS,
|
|
},
|
|
]
|
|
},
|
|
"1D-111111111111": {"sensors": []},
|
|
"22-111111111111": {
|
|
"sensors": [
|
|
{
|
|
"entity_id": "sensor.22_111111111111_temperature",
|
|
"unique_id": "/sys/bus/w1/devices/22-111111111111/w1_slave",
|
|
"injected_value": FileNotFoundError,
|
|
"result": "unknown",
|
|
"unit": TEMP_CELSIUS,
|
|
},
|
|
]
|
|
},
|
|
"28-111111111111": {
|
|
"sensors": [
|
|
{
|
|
"entity_id": "sensor.28_111111111111_temperature",
|
|
"unique_id": "/sys/bus/w1/devices/28-111111111111/w1_slave",
|
|
"injected_value": InvalidCRCException,
|
|
"result": "unknown",
|
|
"unit": TEMP_CELSIUS,
|
|
},
|
|
]
|
|
},
|
|
"3B-111111111111": {
|
|
"sensors": [
|
|
{
|
|
"entity_id": "sensor.3b_111111111111_temperature",
|
|
"unique_id": "/sys/bus/w1/devices/3B-111111111111/w1_slave",
|
|
"injected_value": 29.993,
|
|
"result": "30.0",
|
|
"unit": TEMP_CELSIUS,
|
|
},
|
|
]
|
|
},
|
|
"42-111111111111": {
|
|
"sensors": [
|
|
{
|
|
"entity_id": "sensor.42_111111111111_temperature",
|
|
"unique_id": "/sys/bus/w1/devices/42-111111111111/w1_slave",
|
|
"injected_value": UnsupportResponseException,
|
|
"result": "unknown",
|
|
"unit": TEMP_CELSIUS,
|
|
},
|
|
]
|
|
},
|
|
"EF-111111111111": {
|
|
"sensors": [],
|
|
},
|
|
"EF-111111111112": {
|
|
"sensors": [],
|
|
},
|
|
}
|
|
|
|
|
|
@pytest.mark.parametrize("device_id", MOCK_DEVICE_SENSORS.keys())
|
|
async def test_onewiredirect_setup_valid_device(hass, device_id):
|
|
"""Test that sysbus config entry works correctly."""
|
|
entity_registry = mock_registry(hass)
|
|
|
|
glob_result = [f"/{DEFAULT_SYSBUS_MOUNT_DIR}/{device_id}"]
|
|
read_side_effect = []
|
|
expected_sensors = MOCK_DEVICE_SENSORS[device_id]["sensors"]
|
|
for expected_sensor in expected_sensors:
|
|
read_side_effect.append(expected_sensor["injected_value"])
|
|
|
|
with patch(
|
|
"homeassistant.components.onewire.sensor.os.path.isdir", return_value=True
|
|
), patch("pi1wire._finder.glob.glob", return_value=glob_result,), patch(
|
|
"pi1wire.OneWire.get_temperature",
|
|
side_effect=read_side_effect,
|
|
):
|
|
assert await async_setup_component(hass, SENSOR_DOMAIN, MOCK_CONFIG)
|
|
await hass.async_block_till_done()
|
|
|
|
assert len(entity_registry.entities) == len(expected_sensors)
|
|
|
|
for expected_sensor in expected_sensors:
|
|
entity_id = expected_sensor["entity_id"]
|
|
registry_entry = entity_registry.entities.get(entity_id)
|
|
assert registry_entry is not None
|
|
assert registry_entry.unique_id == expected_sensor["unique_id"]
|
|
assert registry_entry.unit_of_measurement == expected_sensor["unit"]
|
|
state = hass.states.get(entity_id)
|
|
assert state.state == expected_sensor["result"]
|