mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Default some entities to disabled (#42797)
This commit is contained in:
parent
2625a4dfdc
commit
c7cdad2b5a
@ -22,6 +22,7 @@ class OneWire(Entity):
|
||||
sensor_type: str,
|
||||
sensor_name: str = None,
|
||||
device_info=None,
|
||||
default_disabled: bool = False,
|
||||
):
|
||||
"""Initialize the sensor."""
|
||||
self._name = f"{name} {sensor_name or sensor_type.capitalize()}"
|
||||
@ -32,6 +33,7 @@ class OneWire(Entity):
|
||||
self._device_info = device_info
|
||||
self._state = None
|
||||
self._value_raw = None
|
||||
self._default_disabled = default_disabled
|
||||
|
||||
@property
|
||||
def name(self) -> Optional[str]:
|
||||
@ -68,6 +70,11 @@ class OneWire(Entity):
|
||||
"""Return device specific attributes."""
|
||||
return self._device_info
|
||||
|
||||
@property
|
||||
def entity_registry_enabled_default(self) -> bool:
|
||||
"""Return if the entity should be enabled when first added to the entity registry."""
|
||||
return not self._default_disabled
|
||||
|
||||
|
||||
class OneWireProxy(OneWire):
|
||||
"""Implementation of a 1-Wire sensor through owserver."""
|
||||
@ -79,10 +86,13 @@ class OneWireProxy(OneWire):
|
||||
sensor_type: str,
|
||||
sensor_name: str,
|
||||
device_info: Dict[str, Any],
|
||||
disable_startup: bool,
|
||||
owproxy: protocol._Proxy,
|
||||
):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(name, device_file, sensor_type, sensor_name, device_info)
|
||||
super().__init__(
|
||||
name, device_file, sensor_type, sensor_name, device_info, disable_startup
|
||||
)
|
||||
self._owproxy = owproxy
|
||||
|
||||
def _read_value_ownet(self):
|
||||
|
@ -45,44 +45,80 @@ DEVICE_SENSORS = {
|
||||
"path": "TAI8570/temperature",
|
||||
"name": "Temperature",
|
||||
"type": SENSOR_TYPE_TEMPERATURE,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "TAI8570/pressure",
|
||||
"name": "Pressure",
|
||||
"type": SENSOR_TYPE_PRESSURE,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{"path": "TAI8570/pressure", "name": "Pressure", "type": SENSOR_TYPE_PRESSURE},
|
||||
],
|
||||
"22": [
|
||||
{"path": "temperature", "name": "Temperature", "type": SENSOR_TYPE_TEMPERATURE}
|
||||
],
|
||||
"26": [
|
||||
{"path": "temperature", "name": "Temperature", "type": SENSOR_TYPE_TEMPERATURE},
|
||||
{"path": "humidity", "name": "Humidity", "type": SENSOR_TYPE_HUMIDITY},
|
||||
{
|
||||
"path": "humidity",
|
||||
"name": "Humidity",
|
||||
"type": SENSOR_TYPE_HUMIDITY,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "HIH3600/humidity",
|
||||
"name": "Humidity HIH3600",
|
||||
"type": SENSOR_TYPE_HUMIDITY,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "HIH4000/humidity",
|
||||
"name": "Humidity HIH4000",
|
||||
"type": SENSOR_TYPE_HUMIDITY,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "HIH5030/humidity",
|
||||
"name": "Humidity HIH5030",
|
||||
"type": SENSOR_TYPE_HUMIDITY,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "HTM1735/humidity",
|
||||
"name": "Humidity HTM1735",
|
||||
"type": SENSOR_TYPE_HUMIDITY,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "B1-R1-A/pressure",
|
||||
"name": "Pressure",
|
||||
"type": SENSOR_TYPE_PRESSURE,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{"path": "B1-R1-A/pressure", "name": "Pressure", "type": SENSOR_TYPE_PRESSURE},
|
||||
{
|
||||
"path": "S3-R1-A/illuminance",
|
||||
"name": "Illuminance",
|
||||
"type": SENSOR_TYPE_ILLUMINANCE,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "VAD",
|
||||
"name": "Voltage VAD",
|
||||
"type": SENSOR_TYPE_VOLTAGE,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "VDD",
|
||||
"name": "Voltage VDD",
|
||||
"type": SENSOR_TYPE_VOLTAGE,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "IAD",
|
||||
"name": "Current",
|
||||
"type": SENSOR_TYPE_CURRENT,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{"path": "VAD", "name": "Voltage VAD", "type": SENSOR_TYPE_VOLTAGE},
|
||||
{"path": "VDD", "name": "Voltage VDD", "type": SENSOR_TYPE_VOLTAGE},
|
||||
{"path": "IAD", "name": "Current", "type": SENSOR_TYPE_CURRENT},
|
||||
],
|
||||
"28": [
|
||||
{"path": "temperature", "name": "Temperature", "type": SENSOR_TYPE_TEMPERATURE}
|
||||
@ -247,6 +283,7 @@ def get_entities(onewirehub: OneWireHub, config):
|
||||
device_sensor["type"],
|
||||
device_sensor["name"],
|
||||
device_info,
|
||||
device_sensor.get("default_disabled", False),
|
||||
onewirehub.owproxy,
|
||||
)
|
||||
)
|
||||
|
@ -7,6 +7,7 @@ from homeassistant.components.onewire.const import (
|
||||
DOMAIN,
|
||||
PRESSURE_CBAR,
|
||||
)
|
||||
from homeassistant.components.onewire.sensor import DEVICE_SENSORS
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.const import (
|
||||
DEVICE_CLASS_CURRENT,
|
||||
@ -84,6 +85,7 @@ MOCK_DEVICE_SENSORS = {
|
||||
"result": "25.1",
|
||||
"unit": TEMP_CELSIUS,
|
||||
"class": DEVICE_CLASS_TEMPERATURE,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.12_111111111111_pressure",
|
||||
@ -92,6 +94,7 @@ MOCK_DEVICE_SENSORS = {
|
||||
"result": "1025.1",
|
||||
"unit": PRESSURE_MBAR,
|
||||
"class": DEVICE_CLASS_PRESSURE,
|
||||
"disabled": True,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -171,6 +174,7 @@ MOCK_DEVICE_SENSORS = {
|
||||
"result": "72.8",
|
||||
"unit": PERCENTAGE,
|
||||
"class": DEVICE_CLASS_HUMIDITY,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_humidity_hih3600",
|
||||
@ -187,6 +191,7 @@ MOCK_DEVICE_SENSORS = {
|
||||
"result": "74.8",
|
||||
"unit": PERCENTAGE,
|
||||
"class": DEVICE_CLASS_HUMIDITY,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_humidity_hih5030",
|
||||
@ -195,6 +200,7 @@ MOCK_DEVICE_SENSORS = {
|
||||
"result": "75.8",
|
||||
"unit": PERCENTAGE,
|
||||
"class": DEVICE_CLASS_HUMIDITY,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_humidity_htm1735",
|
||||
@ -203,6 +209,7 @@ MOCK_DEVICE_SENSORS = {
|
||||
"result": "unknown",
|
||||
"unit": PERCENTAGE,
|
||||
"class": DEVICE_CLASS_HUMIDITY,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_pressure",
|
||||
@ -211,6 +218,7 @@ MOCK_DEVICE_SENSORS = {
|
||||
"result": "969.3",
|
||||
"unit": PRESSURE_MBAR,
|
||||
"class": DEVICE_CLASS_PRESSURE,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_illuminance",
|
||||
@ -219,6 +227,7 @@ MOCK_DEVICE_SENSORS = {
|
||||
"result": "65.9",
|
||||
"unit": LIGHT_LUX,
|
||||
"class": DEVICE_CLASS_ILLUMINANCE,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_voltage_vad",
|
||||
@ -227,6 +236,7 @@ MOCK_DEVICE_SENSORS = {
|
||||
"result": "3.0",
|
||||
"unit": VOLT,
|
||||
"class": DEVICE_CLASS_VOLTAGE,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_voltage_vdd",
|
||||
@ -235,6 +245,7 @@ MOCK_DEVICE_SENSORS = {
|
||||
"result": "4.7",
|
||||
"unit": VOLT,
|
||||
"class": DEVICE_CLASS_VOLTAGE,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_current",
|
||||
@ -243,6 +254,7 @@ MOCK_DEVICE_SENSORS = {
|
||||
"result": "1.0",
|
||||
"unit": ELECTRICAL_CURRENT_AMPERE,
|
||||
"class": DEVICE_CLASS_CURRENT,
|
||||
"disabled": True,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -418,6 +430,8 @@ async def test_owserver_setup_valid_device(hass, device_id):
|
||||
# Ensure enough read side effect
|
||||
read_side_effect.extend([ProtocolError("Missing injected value")] * 10)
|
||||
|
||||
# Ignore default_disabled for testing
|
||||
DEVICE_SENSORS["26"][2]["default_disabled"] = False
|
||||
with patch("homeassistant.components.onewire.onewirehub.protocol.proxy") as owproxy:
|
||||
owproxy.return_value.dir.return_value = dir_return_value
|
||||
owproxy.return_value.read.side_effect = read_side_effect
|
||||
@ -444,5 +458,9 @@ async def test_owserver_setup_valid_device(hass, device_id):
|
||||
assert registry_entry.unique_id == expected_sensor["unique_id"]
|
||||
assert registry_entry.unit_of_measurement == expected_sensor["unit"]
|
||||
assert registry_entry.device_class == expected_sensor["class"]
|
||||
assert registry_entry.disabled == expected_sensor.get("disabled", False)
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == expected_sensor["result"]
|
||||
if registry_entry.disabled:
|
||||
assert state is None
|
||||
else:
|
||||
assert state.state == expected_sensor["result"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user