Use entity name translations in 1-wire (#90696)

* Use entity name translations in onewire

* Adjust binary sensors

* Adjust switches

* Cleanup
pull/90855/head
epenet 2023-04-03 19:07:02 +02:00 committed by Paulus Schoutsen
parent e38590e40a
commit 71608d4795
7 changed files with 310 additions and 88 deletions

View File

@ -37,8 +37,8 @@ DEVICE_BINARY_SENSORS: dict[str, tuple[OneWireBinarySensorEntityDescription, ...
OneWireBinarySensorEntityDescription(
key=f"sensed.{id}",
entity_registry_enabled_default=False,
name=f"Sensed {id}",
read_mode=READ_MODE_BOOL,
translation_key=f"sensed_{id.lower()}",
)
for id in DEVICE_KEYS_A_B
),
@ -46,8 +46,8 @@ DEVICE_BINARY_SENSORS: dict[str, tuple[OneWireBinarySensorEntityDescription, ...
OneWireBinarySensorEntityDescription(
key=f"sensed.{id}",
entity_registry_enabled_default=False,
name=f"Sensed {id}",
read_mode=READ_MODE_BOOL,
translation_key=f"sensed_{id}",
)
for id in DEVICE_KEYS_0_7
),
@ -55,8 +55,8 @@ DEVICE_BINARY_SENSORS: dict[str, tuple[OneWireBinarySensorEntityDescription, ...
OneWireBinarySensorEntityDescription(
key=f"sensed.{id}",
entity_registry_enabled_default=False,
name=f"Sensed {id}",
read_mode=READ_MODE_BOOL,
translation_key=f"sensed_{id.lower()}",
)
for id in DEVICE_KEYS_A_B
),
@ -69,10 +69,10 @@ HOBBYBOARD_EF: dict[str, tuple[OneWireBinarySensorEntityDescription, ...]] = {
OneWireBinarySensorEntityDescription(
key=f"hub/short.{id}",
entity_registry_enabled_default=False,
name=f"Hub Short on Branch {id}",
read_mode=READ_MODE_BOOL,
entity_category=EntityCategory.DIAGNOSTIC,
device_class=BinarySensorDeviceClass.PROBLEM,
translation_key=f"hub_short_{id}",
)
for id in DEVICE_KEYS_0_3
),
@ -120,14 +120,12 @@ def get_entities(onewire_hub: OneWireHub) -> list[OneWireBinarySensor]:
continue
for description in get_sensor_types(device_sub_type)[family]:
device_file = os.path.join(os.path.split(device.path)[0], description.key)
name = f"{device_id} {description.name}"
entities.append(
OneWireBinarySensor(
description=description,
device_id=device_id,
device_file=device_file,
device_info=device_info,
name=name,
owproxy=onewire_hub.owproxy,
)
)

View File

@ -27,6 +27,7 @@ class OneWireEntity(Entity):
"""Implementation of a 1-Wire entity."""
entity_description: OneWireEntityDescription
_attr_has_entity_name = True
def __init__(
self,
@ -34,7 +35,6 @@ class OneWireEntity(Entity):
device_id: str,
device_info: DeviceInfo,
device_file: str,
name: str,
owproxy: protocol._Proxy,
) -> None:
"""Initialize the entity."""
@ -42,7 +42,6 @@ class OneWireEntity(Entity):
self._last_update_success = True
self._attr_unique_id = f"/{device_id}/{description.key}"
self._attr_device_info = device_info
self._attr_name = name
self._device_file = device_file
self._state: StateType = None
self._value_raw: float | None = None

View File

@ -70,10 +70,10 @@ def _get_sensor_precision_family_28(device_id: str, options: Mapping[str, Any])
SIMPLE_TEMPERATURE_SENSOR_DESCRIPTION = OneWireSensorEntityDescription(
key="temperature",
device_class=SensorDeviceClass.TEMPERATURE,
name="Temperature",
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="temperature",
)
_LOGGER = logging.getLogger(__name__)
@ -86,19 +86,19 @@ DEVICE_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
key="TAI8570/temperature",
device_class=SensorDeviceClass.TEMPERATURE,
entity_registry_enabled_default=False,
name="Temperature",
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="temperature",
),
OneWireSensorEntityDescription(
key="TAI8570/pressure",
device_class=SensorDeviceClass.PRESSURE,
entity_registry_enabled_default=False,
name="Pressure",
native_unit_of_measurement=UnitOfPressure.MBAR,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="pressure",
),
),
"22": (SIMPLE_TEMPERATURE_SENSOR_DESCRIPTION,),
@ -108,102 +108,102 @@ DEVICE_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
key="humidity",
device_class=SensorDeviceClass.HUMIDITY,
entity_registry_enabled_default=False,
name="Humidity",
native_unit_of_measurement=PERCENTAGE,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="humidity",
),
OneWireSensorEntityDescription(
key="HIH3600/humidity",
device_class=SensorDeviceClass.HUMIDITY,
entity_registry_enabled_default=False,
name="Humidity HIH3600",
native_unit_of_measurement=PERCENTAGE,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="humidity_hih3600",
),
OneWireSensorEntityDescription(
key="HIH4000/humidity",
device_class=SensorDeviceClass.HUMIDITY,
entity_registry_enabled_default=False,
name="Humidity HIH4000",
native_unit_of_measurement=PERCENTAGE,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="humidity_hih4000",
),
OneWireSensorEntityDescription(
key="HIH5030/humidity",
device_class=SensorDeviceClass.HUMIDITY,
entity_registry_enabled_default=False,
name="Humidity HIH5030",
native_unit_of_measurement=PERCENTAGE,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="humidity_hih5030",
),
OneWireSensorEntityDescription(
key="HTM1735/humidity",
device_class=SensorDeviceClass.HUMIDITY,
entity_registry_enabled_default=False,
name="Humidity HTM1735",
native_unit_of_measurement=PERCENTAGE,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="humidity_htm1735",
),
OneWireSensorEntityDescription(
key="B1-R1-A/pressure",
device_class=SensorDeviceClass.PRESSURE,
entity_registry_enabled_default=False,
name="Pressure",
native_unit_of_measurement=UnitOfPressure.MBAR,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="pressure",
),
OneWireSensorEntityDescription(
key="S3-R1-A/illuminance",
device_class=SensorDeviceClass.ILLUMINANCE,
entity_registry_enabled_default=False,
name="Illuminance",
native_unit_of_measurement=LIGHT_LUX,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="illuminance",
),
OneWireSensorEntityDescription(
key="VAD",
device_class=SensorDeviceClass.VOLTAGE,
entity_registry_enabled_default=False,
name="Voltage VAD",
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="voltage_vad",
),
OneWireSensorEntityDescription(
key="VDD",
device_class=SensorDeviceClass.VOLTAGE,
entity_registry_enabled_default=False,
name="Voltage VDD",
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="voltage_vdd",
),
OneWireSensorEntityDescription(
key="vis",
device_class=SensorDeviceClass.VOLTAGE,
entity_registry_enabled_default=False,
name="vis",
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="voltage_vis",
),
),
"28": (
OneWireSensorEntityDescription(
key="temperature",
device_class=SensorDeviceClass.TEMPERATURE,
name="Temperature",
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
override_key=_get_sensor_precision_family_28,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="temperature",
),
),
"30": (
@ -212,29 +212,29 @@ DEVICE_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
key="typeX/temperature",
device_class=SensorDeviceClass.TEMPERATURE,
entity_registry_enabled_default=False,
name="Thermocouple temperature",
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
read_mode=READ_MODE_FLOAT,
override_key=lambda d, o: "typeK/temperature",
state_class=SensorStateClass.MEASUREMENT,
translation_key="thermocouple_temperature_k",
),
OneWireSensorEntityDescription(
key="volt",
device_class=SensorDeviceClass.VOLTAGE,
entity_registry_enabled_default=False,
name="Voltage",
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="voltage",
),
OneWireSensorEntityDescription(
key="vis",
device_class=SensorDeviceClass.VOLTAGE,
entity_registry_enabled_default=False,
name="vis",
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="voltage_vis_gradient",
),
),
"3B": (SIMPLE_TEMPERATURE_SENSOR_DESCRIPTION,),
@ -242,10 +242,10 @@ DEVICE_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
"1D": tuple(
OneWireSensorEntityDescription(
key=f"counter.{id}",
name=f"Counter {id}",
native_unit_of_measurement="count",
read_mode=READ_MODE_INT,
state_class=SensorStateClass.TOTAL_INCREASING,
translation_key=f"counter_{id.lower()}",
)
for id in DEVICE_KEYS_A_B
),
@ -258,36 +258,36 @@ HOBBYBOARD_EF: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
OneWireSensorEntityDescription(
key="humidity/humidity_corrected",
device_class=SensorDeviceClass.HUMIDITY,
name="Humidity",
native_unit_of_measurement=PERCENTAGE,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="humidity",
),
OneWireSensorEntityDescription(
key="humidity/humidity_raw",
device_class=SensorDeviceClass.HUMIDITY,
name="Humidity Raw",
native_unit_of_measurement=PERCENTAGE,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="humidity_raw",
),
OneWireSensorEntityDescription(
key="humidity/temperature",
device_class=SensorDeviceClass.TEMPERATURE,
name="Temperature",
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="temperature",
),
),
"HB_MOISTURE_METER": tuple(
OneWireSensorEntityDescription(
key=f"moisture/sensor.{id}",
device_class=SensorDeviceClass.PRESSURE,
name=f"Moisture {id}",
native_unit_of_measurement=UnitOfPressure.CBAR,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key=f"moisture_{id}",
)
for id in DEVICE_KEYS_0_3
),
@ -300,52 +300,52 @@ EDS_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
OneWireSensorEntityDescription(
key="EDS0066/temperature",
device_class=SensorDeviceClass.TEMPERATURE,
name="Temperature",
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="temperature",
),
OneWireSensorEntityDescription(
key="EDS0066/pressure",
device_class=SensorDeviceClass.PRESSURE,
name="Pressure",
native_unit_of_measurement=UnitOfPressure.MBAR,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="pressure",
),
),
"EDS0068": (
OneWireSensorEntityDescription(
key="EDS0068/temperature",
device_class=SensorDeviceClass.TEMPERATURE,
name="Temperature",
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="temperature",
),
OneWireSensorEntityDescription(
key="EDS0068/pressure",
device_class=SensorDeviceClass.PRESSURE,
name="Pressure",
native_unit_of_measurement=UnitOfPressure.MBAR,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="pressure",
),
OneWireSensorEntityDescription(
key="EDS0068/light",
device_class=SensorDeviceClass.ILLUMINANCE,
name="Illuminance",
native_unit_of_measurement=LIGHT_LUX,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="illuminance",
),
OneWireSensorEntityDescription(
key="EDS0068/humidity",
device_class=SensorDeviceClass.HUMIDITY,
name="Humidity",
native_unit_of_measurement=PERCENTAGE,
read_mode=READ_MODE_FLOAT,
state_class=SensorStateClass.MEASUREMENT,
translation_key="humidity",
),
),
}
@ -412,7 +412,8 @@ def get_entities(
description = copy.deepcopy(description)
description.device_class = SensorDeviceClass.HUMIDITY
description.native_unit_of_measurement = PERCENTAGE
description.name = f"Wetness {s_id}"
description.translation_key = f"wetness_{s_id}"
_LOGGER.info(description.translation_key)
override_key = None
if description.override_key:
override_key = description.override_key(device_id, options)
@ -420,7 +421,6 @@ def get_entities(
os.path.split(device.path)[0],
override_key or description.key,
)
name = f"{device_id} {description.name}"
if family == "12":
# We need to check if there is TAI8570 plugged in
try:
@ -438,7 +438,6 @@ def get_entities(
device_id=device_id,
device_file=device_file,
device_info=device_info,
name=name,
owproxy=onewire_hub.owproxy,
)
)

View File

@ -16,6 +16,233 @@
}
}
},
"entity": {
"binary_sensor": {
"sensed_a": {
"name": "Sensed A"
},
"sensed_b": {
"name": "Sensed B"
},
"sensed_0": {
"name": "Sensed 0"
},
"sensed_1": {
"name": "Sensed 1"
},
"sensed_2": {
"name": "Sensed 2"
},
"sensed_3": {
"name": "Sensed 3"
},
"sensed_4": {
"name": "Sensed 4"
},
"sensed_5": {
"name": "Sensed 5"
},
"sensed_6": {
"name": "Sensed 6"
},
"sensed_7": {
"name": "Sensed 7"
},
"hub_short_0": {
"name": "Hub short on branch 0"
},
"hub_short_1": {
"name": "Hub short on branch 1"
},
"hub_short_2": {
"name": "Hub short on branch 2"
},
"hub_short_3": {
"name": "Hub short on branch 3"
}
},
"sensor": {
"counter_a": {
"name": "Counter A"
},
"counter_b": {
"name": "Counter B"
},
"humidity": {
"name": "[%key:component::sensor::entity_component::humidity::name%]"
},
"humidity_hih3600": {
"name": "HIH3600 humidity"
},
"humidity_hih4000": {
"name": "HIH4000 humidity"
},
"humidity_hih5030": {
"name": "HIH5030 humidity"
},
"humidity_htm1735": {
"name": "HTM1735 humidity"
},
"humidity_raw": {
"name": "Raw humidity"
},
"illuminance": {
"name": "[%key:component::sensor::entity_component::illuminance::name%]"
},
"moisture_1": {
"name": "Moisture 1"
},
"moisture_2": {
"name": "Moisture 2"
},
"moisture_3": {
"name": "Moisture 3"
},
"moisture_4": {
"name": "Moisture 4"
},
"pressure": {
"name": "[%key:component::sensor::entity_component::pressure::name%]"
},
"temperature": {
"name": "[%key:component::sensor::entity_component::temperature::name%]"
},
"thermocouple_temperature_k": {
"name": "Thermocouple K temperature"
},
"voltage": {
"name": "[%key:component::sensor::entity_component::voltage::name%]"
},
"voltage_vad": {
"name": "VAD voltage"
},
"voltage_vdd": {
"name": "VDD voltage"
},
"voltage_vis": {
"name": "VIS voltage difference"
},
"voltage_vis_gradient": {
"name": "VIS voltage gradient"
},
"wetness_0": {
"name": "Wetness 0"
},
"wetness_1": {
"name": "Wetness 1"
},
"wetness_2": {
"name": "Wetness 2"
},
"wetness_3": {
"name": "Wetness 3"
}
},
"switch": {
"hub_branch_0": {
"name": "Hub branch 0"
},
"hub_branch_1": {
"name": "Hub branch 1"
},
"hub_branch_2": {
"name": "Hub branch 2"
},
"hub_branch_3": {
"name": "Hub branch 3"
},
"iad": {
"name": "Current A/D control"
},
"latch_0": {
"name": "Latch 0"
},
"latch_1": {
"name": "Latch 1"
},
"latch_2": {
"name": "Latch 2"
},
"latch_3": {
"name": "Latch 3"
},
"latch_4": {
"name": "Latch 4"
},
"latch_5": {
"name": "Latch 5"
},
"latch_6": {
"name": "Latch 6"
},
"latch_7": {
"name": "Latch 7"
},
"latch_a": {
"name": "Latch A"
},
"latch_b": {
"name": "Latch B"
},
"leaf_sensor_0": {
"name": "Leaf sensor 0"
},
"leaf_sensor_1": {
"name": "Leaf sensor 1"
},
"leaf_sensor_2": {
"name": "Leaf sensor 2"
},
"leaf_sensor_3": {
"name": "Leaf sensor 3"
},
"moisture_sensor_0": {
"name": "Moisture sensor 0"
},
"moisture_sensor_1": {
"name": "Moisture sensor 1"
},
"moisture_sensor_2": {
"name": "Moisture sensor 2"
},
"moisture_sensor_3": {
"name": "Moisture sensor 3"
},
"pio": {
"name": "Programmed input-output"
},
"pio_0": {
"name": "Programmed input-output 0"
},
"pio_1": {
"name": "Programmed input-output 1"
},
"pio_2": {
"name": "Programmed input-output 2"
},
"pio_3": {
"name": "Programmed input-output 3"
},
"pio_4": {
"name": "Programmed input-output 4"
},
"pio_5": {
"name": "Programmed input-output 5"
},
"pio_6": {
"name": "Programmed input-output 6"
},
"pio_7": {
"name": "Programmed input-output 7"
},
"pio_a": {
"name": "Programmed input-output A"
},
"pio_b": {
"name": "Programmed input-output B"
}
}
},
"options": {
"error": {
"device_not_selected": "Select devices to configure"

View File

@ -32,8 +32,8 @@ DEVICE_SWITCHES: dict[str, tuple[OneWireEntityDescription, ...]] = {
OneWireSwitchEntityDescription(
key="PIO",
entity_registry_enabled_default=False,
name="PIO",
read_mode=READ_MODE_BOOL,
translation_key="pio",
),
),
"12": tuple(
@ -41,8 +41,8 @@ DEVICE_SWITCHES: dict[str, tuple[OneWireEntityDescription, ...]] = {
OneWireSwitchEntityDescription(
key=f"PIO.{id}",
entity_registry_enabled_default=False,
name=f"PIO {id}",
read_mode=READ_MODE_BOOL,
translation_key=f"pio_{id.lower()}",
)
for id in DEVICE_KEYS_A_B
]
@ -50,8 +50,8 @@ DEVICE_SWITCHES: dict[str, tuple[OneWireEntityDescription, ...]] = {
OneWireSwitchEntityDescription(
key=f"latch.{id}",
entity_registry_enabled_default=False,
name=f"Latch {id}",
read_mode=READ_MODE_BOOL,
translation_key=f"latch_{id.lower()}",
)
for id in DEVICE_KEYS_A_B
]
@ -61,8 +61,8 @@ DEVICE_SWITCHES: dict[str, tuple[OneWireEntityDescription, ...]] = {
key="IAD",
entity_registry_enabled_default=False,
entity_category=EntityCategory.CONFIG,
name="IAD",
read_mode=READ_MODE_BOOL,
translation_key="iad",
),
),
"29": tuple(
@ -70,8 +70,8 @@ DEVICE_SWITCHES: dict[str, tuple[OneWireEntityDescription, ...]] = {
OneWireSwitchEntityDescription(
key=f"PIO.{id}",
entity_registry_enabled_default=False,
name=f"PIO {id}",
read_mode=READ_MODE_BOOL,
translation_key=f"pio_{id}",
)
for id in DEVICE_KEYS_0_7
]
@ -79,8 +79,8 @@ DEVICE_SWITCHES: dict[str, tuple[OneWireEntityDescription, ...]] = {
OneWireSwitchEntityDescription(
key=f"latch.{id}",
entity_registry_enabled_default=False,
name=f"Latch {id}",
read_mode=READ_MODE_BOOL,
translation_key=f"latch_{id}",
)
for id in DEVICE_KEYS_0_7
]
@ -89,8 +89,8 @@ DEVICE_SWITCHES: dict[str, tuple[OneWireEntityDescription, ...]] = {
OneWireSwitchEntityDescription(
key=f"PIO.{id}",
entity_registry_enabled_default=False,
name=f"PIO {id}",
read_mode=READ_MODE_BOOL,
translation_key=f"pio_{id.lower()}",
)
for id in DEVICE_KEYS_A_B
),
@ -104,9 +104,9 @@ HOBBYBOARD_EF: dict[str, tuple[OneWireEntityDescription, ...]] = {
OneWireSwitchEntityDescription(
key=f"hub/branch.{id}",
entity_registry_enabled_default=False,
name=f"Hub Branch {id} Enable",
read_mode=READ_MODE_BOOL,
entity_category=EntityCategory.CONFIG,
translation_key=f"hub_branch_{id}",
)
for id in DEVICE_KEYS_0_3
),
@ -115,9 +115,9 @@ HOBBYBOARD_EF: dict[str, tuple[OneWireEntityDescription, ...]] = {
OneWireSwitchEntityDescription(
key=f"moisture/is_leaf.{id}",
entity_registry_enabled_default=False,
name=f"Leaf Sensor {id} Enable",
read_mode=READ_MODE_BOOL,
entity_category=EntityCategory.CONFIG,
translation_key=f"leaf_sensor_{id}",
)
for id in DEVICE_KEYS_0_3
]
@ -125,9 +125,9 @@ HOBBYBOARD_EF: dict[str, tuple[OneWireEntityDescription, ...]] = {
OneWireSwitchEntityDescription(
key=f"moisture/is_moisture.{id}",
entity_registry_enabled_default=False,
name=f"Moisture Sensor {id} Enable",
read_mode=READ_MODE_BOOL,
entity_category=EntityCategory.CONFIG,
translation_key=f"moisture_sensor_{id}",
)
for id in DEVICE_KEYS_0_3
]
@ -177,14 +177,12 @@ def get_entities(onewire_hub: OneWireHub) -> list[OneWireSwitch]:
continue
for description in get_sensor_types(device_sub_type)[family]:
device_file = os.path.join(os.path.split(device.path)[0], description.key)
name = f"{device_id} {description.name}"
entities.append(
OneWireSwitch(
description=description,
device_id=device_id,
device_file=device_file,
device_info=device_info,
name=name,
owproxy=onewire_hub.owproxy,
)
)

View File

@ -40,6 +40,7 @@ def check_and_enable_disabled_entities(
if expected_entity.get(ATTR_DEFAULT_DISABLED):
entity_id = expected_entity[ATTR_ENTITY_ID]
registry_entry = entity_registry.entities.get(entity_id)
assert registry_entry, f"{entity_id} not found in registry"
assert registry_entry.disabled
assert registry_entry.disabled_by is RegistryEntryDisabler.INTEGRATION
entity_registry.async_update_entity(entity_id, **{"disabled_by": None})
@ -76,7 +77,7 @@ def check_entities(
for expected_entity in expected_entities:
entity_id = expected_entity[ATTR_ENTITY_ID]
registry_entry = entity_registry.entities.get(entity_id)
assert registry_entry is not None
assert registry_entry is not None, f"{entity_id} not found in registry"
assert registry_entry.entity_category == expected_entity.get(
ATTR_ENTITY_CATEGORY
)

View File

@ -70,7 +70,7 @@ MOCK_OWPROXY_DEVICES = {
Platform.SWITCH: [
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_ID: "switch.05_111111111111_pio",
ATTR_ENTITY_ID: "switch.05_111111111111_programmed_input_output",
ATTR_INJECT_READS: b" 1",
ATTR_STATE: STATE_ON,
ATTR_UNIQUE_ID: "/05.111111111111/PIO",
@ -150,14 +150,14 @@ MOCK_OWPROXY_DEVICES = {
Platform.SWITCH: [
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_ID: "switch.12_111111111111_pio_a",
ATTR_ENTITY_ID: "switch.12_111111111111_programmed_input_output_a",
ATTR_INJECT_READS: b" 1",
ATTR_STATE: STATE_ON,
ATTR_UNIQUE_ID: "/12.111111111111/PIO.A",
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_ID: "switch.12_111111111111_pio_b",
ATTR_ENTITY_ID: "switch.12_111111111111_programmed_input_output_b",
ATTR_INJECT_READS: b" 0",
ATTR_STATE: STATE_OFF,
ATTR_UNIQUE_ID: "/12.111111111111/PIO.B",
@ -312,7 +312,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_DEVICE_CLASS: SensorDeviceClass.HUMIDITY,
ATTR_ENTITY_ID: "sensor.26_111111111111_humidity_hih3600",
ATTR_ENTITY_ID: "sensor.26_111111111111_hih3600_humidity",
ATTR_INJECT_READS: b" 73.7563",
ATTR_STATE: "73.8",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
@ -322,7 +322,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_DEVICE_CLASS: SensorDeviceClass.HUMIDITY,
ATTR_ENTITY_ID: "sensor.26_111111111111_humidity_hih4000",
ATTR_ENTITY_ID: "sensor.26_111111111111_hih4000_humidity",
ATTR_INJECT_READS: b" 74.7563",
ATTR_STATE: "74.8",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
@ -332,7 +332,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_DEVICE_CLASS: SensorDeviceClass.HUMIDITY,
ATTR_ENTITY_ID: "sensor.26_111111111111_humidity_hih5030",
ATTR_ENTITY_ID: "sensor.26_111111111111_hih5030_humidity",
ATTR_INJECT_READS: b" 75.7563",
ATTR_STATE: "75.8",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
@ -342,7 +342,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_DEVICE_CLASS: SensorDeviceClass.HUMIDITY,
ATTR_ENTITY_ID: "sensor.26_111111111111_humidity_htm1735",
ATTR_ENTITY_ID: "sensor.26_111111111111_htm1735_humidity",
ATTR_INJECT_READS: ProtocolError,
ATTR_STATE: STATE_UNKNOWN,
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
@ -372,7 +372,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_DEVICE_CLASS: SensorDeviceClass.VOLTAGE,
ATTR_ENTITY_ID: "sensor.26_111111111111_voltage_vad",
ATTR_ENTITY_ID: "sensor.26_111111111111_vad_voltage",
ATTR_INJECT_READS: b" 2.97",
ATTR_STATE: "3.0",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
@ -382,7 +382,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_DEVICE_CLASS: SensorDeviceClass.VOLTAGE,
ATTR_ENTITY_ID: "sensor.26_111111111111_voltage_vdd",
ATTR_ENTITY_ID: "sensor.26_111111111111_vdd_voltage",
ATTR_INJECT_READS: b" 4.74",
ATTR_STATE: "4.7",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
@ -392,7 +392,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_DEVICE_CLASS: SensorDeviceClass.VOLTAGE,
ATTR_ENTITY_ID: "sensor.26_111111111111_vis",
ATTR_ENTITY_ID: "sensor.26_111111111111_vis_voltage_difference",
ATTR_INJECT_READS: b" 0.12",
ATTR_STATE: "0.1",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
@ -404,7 +404,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_CATEGORY: EntityCategory.CONFIG,
ATTR_ENTITY_ID: "switch.26_111111111111_iad",
ATTR_ENTITY_ID: "switch.26_111111111111_current_a_d_control",
ATTR_INJECT_READS: b" 1",
ATTR_STATE: STATE_ON,
ATTR_UNIQUE_ID: "/26.111111111111/IAD",
@ -552,56 +552,56 @@ MOCK_OWPROXY_DEVICES = {
Platform.SWITCH: [
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_ID: "switch.29_111111111111_pio_0",
ATTR_ENTITY_ID: "switch.29_111111111111_programmed_input_output_0",
ATTR_INJECT_READS: b" 1",
ATTR_STATE: STATE_ON,
ATTR_UNIQUE_ID: "/29.111111111111/PIO.0",
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_ID: "switch.29_111111111111_pio_1",
ATTR_ENTITY_ID: "switch.29_111111111111_programmed_input_output_1",
ATTR_INJECT_READS: b" 0",
ATTR_STATE: STATE_OFF,
ATTR_UNIQUE_ID: "/29.111111111111/PIO.1",
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_ID: "switch.29_111111111111_pio_2",
ATTR_ENTITY_ID: "switch.29_111111111111_programmed_input_output_2",
ATTR_INJECT_READS: b" 1",
ATTR_STATE: STATE_ON,
ATTR_UNIQUE_ID: "/29.111111111111/PIO.2",
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_ID: "switch.29_111111111111_pio_3",
ATTR_ENTITY_ID: "switch.29_111111111111_programmed_input_output_3",
ATTR_INJECT_READS: b" 0",
ATTR_STATE: STATE_OFF,
ATTR_UNIQUE_ID: "/29.111111111111/PIO.3",
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_ID: "switch.29_111111111111_pio_4",
ATTR_ENTITY_ID: "switch.29_111111111111_programmed_input_output_4",
ATTR_INJECT_READS: b" 1",
ATTR_STATE: STATE_ON,
ATTR_UNIQUE_ID: "/29.111111111111/PIO.4",
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_ID: "switch.29_111111111111_pio_5",
ATTR_ENTITY_ID: "switch.29_111111111111_programmed_input_output_5",
ATTR_INJECT_READS: b" 0",
ATTR_STATE: STATE_OFF,
ATTR_UNIQUE_ID: "/29.111111111111/PIO.5",
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_ID: "switch.29_111111111111_pio_6",
ATTR_ENTITY_ID: "switch.29_111111111111_programmed_input_output_6",
ATTR_INJECT_READS: b" 1",
ATTR_STATE: STATE_ON,
ATTR_UNIQUE_ID: "/29.111111111111/PIO.6",
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_ID: "switch.29_111111111111_pio_7",
ATTR_ENTITY_ID: "switch.29_111111111111_programmed_input_output_7",
ATTR_INJECT_READS: b" 0",
ATTR_STATE: STATE_OFF,
ATTR_UNIQUE_ID: "/29.111111111111/PIO.7",
@ -688,7 +688,7 @@ MOCK_OWPROXY_DEVICES = {
ATTR_DEFAULT_DISABLED: True,
ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
ATTR_DEVICE_FILE: "/30.111111111111/typeK/temperature",
ATTR_ENTITY_ID: "sensor.30_111111111111_thermocouple_temperature",
ATTR_ENTITY_ID: "sensor.30_111111111111_thermocouple_k_temperature",
ATTR_INJECT_READS: b" 173.7563",
ATTR_STATE: "173.8",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
@ -708,7 +708,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_DEVICE_CLASS: SensorDeviceClass.VOLTAGE,
ATTR_ENTITY_ID: "sensor.30_111111111111_vis",
ATTR_ENTITY_ID: "sensor.30_111111111111_vis_voltage_gradient",
ATTR_INJECT_READS: b" 0.12",
ATTR_STATE: "0.1",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
@ -746,14 +746,14 @@ MOCK_OWPROXY_DEVICES = {
Platform.SWITCH: [
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_ID: "switch.3a_111111111111_pio_a",
ATTR_ENTITY_ID: "switch.3a_111111111111_programmed_input_output_a",
ATTR_INJECT_READS: b" 1",
ATTR_STATE: STATE_ON,
ATTR_UNIQUE_ID: "/3A.111111111111/PIO.A",
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_ID: "switch.3a_111111111111_pio_b",
ATTR_ENTITY_ID: "switch.3a_111111111111_programmed_input_output_b",
ATTR_INJECT_READS: b" 0",
ATTR_STATE: STATE_OFF,
ATTR_UNIQUE_ID: "/3A.111111111111/PIO.B",
@ -826,7 +826,7 @@ MOCK_OWPROXY_DEVICES = {
},
{
ATTR_DEVICE_CLASS: SensorDeviceClass.HUMIDITY,
ATTR_ENTITY_ID: "sensor.ef_111111111111_humidity_raw",
ATTR_ENTITY_ID: "sensor.ef_111111111111_raw_humidity",
ATTR_INJECT_READS: b" 65.541",
ATTR_STATE: "65.5",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
@ -900,7 +900,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_CATEGORY: EntityCategory.CONFIG,
ATTR_ENTITY_ID: "switch.ef_111111111112_leaf_sensor_0_enable",
ATTR_ENTITY_ID: "switch.ef_111111111112_leaf_sensor_0",
ATTR_INJECT_READS: b"1",
ATTR_STATE: STATE_ON,
ATTR_UNIQUE_ID: "/EF.111111111112/moisture/is_leaf.0",
@ -908,7 +908,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_CATEGORY: EntityCategory.CONFIG,
ATTR_ENTITY_ID: "switch.ef_111111111112_leaf_sensor_1_enable",
ATTR_ENTITY_ID: "switch.ef_111111111112_leaf_sensor_1",
ATTR_INJECT_READS: b"1",
ATTR_STATE: STATE_ON,
ATTR_UNIQUE_ID: "/EF.111111111112/moisture/is_leaf.1",
@ -916,7 +916,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_CATEGORY: EntityCategory.CONFIG,
ATTR_ENTITY_ID: "switch.ef_111111111112_leaf_sensor_2_enable",
ATTR_ENTITY_ID: "switch.ef_111111111112_leaf_sensor_2",
ATTR_INJECT_READS: b"0",
ATTR_STATE: STATE_OFF,
ATTR_UNIQUE_ID: "/EF.111111111112/moisture/is_leaf.2",
@ -924,7 +924,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_CATEGORY: EntityCategory.CONFIG,
ATTR_ENTITY_ID: "switch.ef_111111111112_leaf_sensor_3_enable",
ATTR_ENTITY_ID: "switch.ef_111111111112_leaf_sensor_3",
ATTR_INJECT_READS: b"0",
ATTR_STATE: STATE_OFF,
ATTR_UNIQUE_ID: "/EF.111111111112/moisture/is_leaf.3",
@ -932,7 +932,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_CATEGORY: EntityCategory.CONFIG,
ATTR_ENTITY_ID: "switch.ef_111111111112_moisture_sensor_0_enable",
ATTR_ENTITY_ID: "switch.ef_111111111112_moisture_sensor_0",
ATTR_INJECT_READS: b"1",
ATTR_STATE: STATE_ON,
ATTR_UNIQUE_ID: "/EF.111111111112/moisture/is_moisture.0",
@ -940,7 +940,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_CATEGORY: EntityCategory.CONFIG,
ATTR_ENTITY_ID: "switch.ef_111111111112_moisture_sensor_1_enable",
ATTR_ENTITY_ID: "switch.ef_111111111112_moisture_sensor_1",
ATTR_INJECT_READS: b"1",
ATTR_STATE: STATE_ON,
ATTR_UNIQUE_ID: "/EF.111111111112/moisture/is_moisture.1",
@ -948,7 +948,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_CATEGORY: EntityCategory.CONFIG,
ATTR_ENTITY_ID: "switch.ef_111111111112_moisture_sensor_2_enable",
ATTR_ENTITY_ID: "switch.ef_111111111112_moisture_sensor_2",
ATTR_INJECT_READS: b"0",
ATTR_STATE: STATE_OFF,
ATTR_UNIQUE_ID: "/EF.111111111112/moisture/is_moisture.2",
@ -956,7 +956,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_CATEGORY: EntityCategory.CONFIG,
ATTR_ENTITY_ID: "switch.ef_111111111112_moisture_sensor_3_enable",
ATTR_ENTITY_ID: "switch.ef_111111111112_moisture_sensor_3",
ATTR_INJECT_READS: b"0",
ATTR_STATE: STATE_OFF,
ATTR_UNIQUE_ID: "/EF.111111111112/moisture/is_moisture.3",
@ -1015,7 +1015,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_CATEGORY: EntityCategory.CONFIG,
ATTR_ENTITY_ID: "switch.ef_111111111113_hub_branch_0_enable",
ATTR_ENTITY_ID: "switch.ef_111111111113_hub_branch_0",
ATTR_INJECT_READS: b"1",
ATTR_STATE: STATE_ON,
ATTR_UNIQUE_ID: "/EF.111111111113/hub/branch.0",
@ -1023,7 +1023,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_CATEGORY: EntityCategory.CONFIG,
ATTR_ENTITY_ID: "switch.ef_111111111113_hub_branch_1_enable",
ATTR_ENTITY_ID: "switch.ef_111111111113_hub_branch_1",
ATTR_INJECT_READS: b"0",
ATTR_STATE: STATE_OFF,
ATTR_UNIQUE_ID: "/EF.111111111113/hub/branch.1",
@ -1031,7 +1031,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_CATEGORY: EntityCategory.CONFIG,
ATTR_ENTITY_ID: "switch.ef_111111111113_hub_branch_2_enable",
ATTR_ENTITY_ID: "switch.ef_111111111113_hub_branch_2",
ATTR_INJECT_READS: b"1",
ATTR_STATE: STATE_ON,
ATTR_UNIQUE_ID: "/EF.111111111113/hub/branch.2",
@ -1039,7 +1039,7 @@ MOCK_OWPROXY_DEVICES = {
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_CATEGORY: EntityCategory.CONFIG,
ATTR_ENTITY_ID: "switch.ef_111111111113_hub_branch_3_enable",
ATTR_ENTITY_ID: "switch.ef_111111111113_hub_branch_3",
ATTR_INJECT_READS: b"0",
ATTR_STATE: STATE_OFF,
ATTR_UNIQUE_ID: "/EF.111111111113/hub/branch.3",