mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 18:27:51 +00:00
Use EntityDescription - onewire (#55003)
This commit is contained in:
parent
2796f65453
commit
ccaf0d5c75
@ -1,9 +1,13 @@
|
||||
"""Support for 1-Wire binary sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
import os
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorEntity,
|
||||
BinarySensorEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_IDENTIFIERS,
|
||||
@ -16,77 +20,83 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import CONF_TYPE_OWSERVER, DOMAIN, SENSOR_TYPE_SENSED
|
||||
from .model import DeviceComponentDescription
|
||||
from .onewire_entities import OneWireBaseEntity, OneWireProxyEntity
|
||||
from .const import CONF_TYPE_OWSERVER, DOMAIN, READ_MODE_BOOL
|
||||
from .onewire_entities import OneWireEntityDescription, OneWireProxyEntity
|
||||
from .onewirehub import OneWireHub
|
||||
|
||||
DEVICE_BINARY_SENSORS: dict[str, list[DeviceComponentDescription]] = {
|
||||
# Family : { path, sensor_type }
|
||||
"12": [
|
||||
{
|
||||
"path": "sensed.A",
|
||||
"name": "Sensed A",
|
||||
"type": SENSOR_TYPE_SENSED,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "sensed.B",
|
||||
"name": "Sensed B",
|
||||
"type": SENSOR_TYPE_SENSED,
|
||||
"default_disabled": True,
|
||||
},
|
||||
],
|
||||
"29": [
|
||||
{
|
||||
"path": "sensed.0",
|
||||
"name": "Sensed 0",
|
||||
"type": SENSOR_TYPE_SENSED,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "sensed.1",
|
||||
"name": "Sensed 1",
|
||||
"type": SENSOR_TYPE_SENSED,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "sensed.2",
|
||||
"name": "Sensed 2",
|
||||
"type": SENSOR_TYPE_SENSED,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "sensed.3",
|
||||
"name": "Sensed 3",
|
||||
"type": SENSOR_TYPE_SENSED,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "sensed.4",
|
||||
"name": "Sensed 4",
|
||||
"type": SENSOR_TYPE_SENSED,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "sensed.5",
|
||||
"name": "Sensed 5",
|
||||
"type": SENSOR_TYPE_SENSED,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "sensed.6",
|
||||
"name": "Sensed 6",
|
||||
"type": SENSOR_TYPE_SENSED,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "sensed.7",
|
||||
"name": "Sensed 7",
|
||||
"type": SENSOR_TYPE_SENSED,
|
||||
"default_disabled": True,
|
||||
},
|
||||
],
|
||||
|
||||
@dataclass
|
||||
class OneWireBinarySensorEntityDescription(
|
||||
OneWireEntityDescription, BinarySensorEntityDescription
|
||||
):
|
||||
"""Class describing OneWire binary sensor entities."""
|
||||
|
||||
|
||||
DEVICE_BINARY_SENSORS: dict[str, tuple[OneWireBinarySensorEntityDescription, ...]] = {
|
||||
"12": (
|
||||
OneWireBinarySensorEntityDescription(
|
||||
key="sensed.A",
|
||||
entity_registry_enabled_default=False,
|
||||
name="Sensed A",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireBinarySensorEntityDescription(
|
||||
key="sensed.B",
|
||||
entity_registry_enabled_default=False,
|
||||
name="Sensed B",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
),
|
||||
"29": (
|
||||
OneWireBinarySensorEntityDescription(
|
||||
key="sensed.0",
|
||||
entity_registry_enabled_default=False,
|
||||
name="Sensed 0",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireBinarySensorEntityDescription(
|
||||
key="sensed.1",
|
||||
entity_registry_enabled_default=False,
|
||||
name="Sensed 1",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireBinarySensorEntityDescription(
|
||||
key="sensed.2",
|
||||
entity_registry_enabled_default=False,
|
||||
name="Sensed 2",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireBinarySensorEntityDescription(
|
||||
key="sensed.3",
|
||||
entity_registry_enabled_default=False,
|
||||
name="Sensed 3",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireBinarySensorEntityDescription(
|
||||
key="sensed.4",
|
||||
entity_registry_enabled_default=False,
|
||||
name="Sensed 4",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireBinarySensorEntityDescription(
|
||||
key="sensed.5",
|
||||
entity_registry_enabled_default=False,
|
||||
name="Sensed 5",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireBinarySensorEntityDescription(
|
||||
key="sensed.6",
|
||||
entity_registry_enabled_default=False,
|
||||
name="Sensed 6",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireBinarySensorEntityDescription(
|
||||
key="sensed.7",
|
||||
entity_registry_enabled_default=False,
|
||||
name="Sensed 7",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
@ -104,12 +114,12 @@ async def async_setup_entry(
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
||||
def get_entities(onewirehub: OneWireHub) -> list[OneWireBaseEntity]:
|
||||
def get_entities(onewirehub: OneWireHub) -> list[BinarySensorEntity]:
|
||||
"""Get a list of entities."""
|
||||
if not onewirehub.devices:
|
||||
return []
|
||||
|
||||
entities: list[OneWireBaseEntity] = []
|
||||
entities: list[BinarySensorEntity] = []
|
||||
|
||||
for device in onewirehub.devices:
|
||||
family = device["family"]
|
||||
@ -124,17 +134,18 @@ def get_entities(onewirehub: OneWireHub) -> list[OneWireBaseEntity]:
|
||||
ATTR_MODEL: device_type,
|
||||
ATTR_NAME: device_id,
|
||||
}
|
||||
for entity_specs in DEVICE_BINARY_SENSORS[family]:
|
||||
entity_path = os.path.join(
|
||||
os.path.split(device["path"])[0], entity_specs["path"]
|
||||
for description in DEVICE_BINARY_SENSORS[family]:
|
||||
device_file = os.path.join(
|
||||
os.path.split(device["path"])[0], description.key
|
||||
)
|
||||
name = f"{device_id} {description.name}"
|
||||
entities.append(
|
||||
OneWireProxyBinarySensor(
|
||||
description=description,
|
||||
device_id=device_id,
|
||||
device_name=device_id,
|
||||
device_file=device_file,
|
||||
device_info=device_info,
|
||||
entity_path=entity_path,
|
||||
entity_specs=entity_specs,
|
||||
name=name,
|
||||
owproxy=onewirehub.owproxy,
|
||||
)
|
||||
)
|
||||
@ -145,6 +156,8 @@ def get_entities(onewirehub: OneWireHub) -> list[OneWireBaseEntity]:
|
||||
class OneWireProxyBinarySensor(OneWireProxyEntity, BinarySensorEntity):
|
||||
"""Implementation of a 1-Wire binary sensor."""
|
||||
|
||||
entity_description: OneWireBinarySensorEntityDescription
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if sensor is on."""
|
||||
|
@ -4,20 +4,6 @@ from __future__ import annotations
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||
from homeassistant.const import (
|
||||
DEVICE_CLASS_CURRENT,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_ILLUMINANCE,
|
||||
DEVICE_CLASS_PRESSURE,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
DEVICE_CLASS_VOLTAGE,
|
||||
ELECTRIC_CURRENT_AMPERE,
|
||||
ELECTRIC_POTENTIAL_VOLT,
|
||||
LIGHT_LUX,
|
||||
PERCENTAGE,
|
||||
PRESSURE_MBAR,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
|
||||
CONF_MOUNT_DIR = "mount_dir"
|
||||
CONF_NAMES = "names"
|
||||
@ -33,34 +19,9 @@ DOMAIN = "onewire"
|
||||
|
||||
PRESSURE_CBAR = "cbar"
|
||||
|
||||
SENSOR_TYPE_COUNT = "count"
|
||||
SENSOR_TYPE_CURRENT = "current"
|
||||
SENSOR_TYPE_HUMIDITY = "humidity"
|
||||
SENSOR_TYPE_ILLUMINANCE = "illuminance"
|
||||
SENSOR_TYPE_MOISTURE = "moisture"
|
||||
SENSOR_TYPE_PRESSURE = "pressure"
|
||||
SENSOR_TYPE_SENSED = "sensed"
|
||||
SENSOR_TYPE_TEMPERATURE = "temperature"
|
||||
SENSOR_TYPE_VOLTAGE = "voltage"
|
||||
SENSOR_TYPE_WETNESS = "wetness"
|
||||
SWITCH_TYPE_LATCH = "latch"
|
||||
SWITCH_TYPE_PIO = "pio"
|
||||
|
||||
SENSOR_TYPES: dict[str, list[str | None]] = {
|
||||
# SensorType: [ Unit, DeviceClass ]
|
||||
SENSOR_TYPE_TEMPERATURE: [TEMP_CELSIUS, DEVICE_CLASS_TEMPERATURE],
|
||||
SENSOR_TYPE_HUMIDITY: [PERCENTAGE, DEVICE_CLASS_HUMIDITY],
|
||||
SENSOR_TYPE_PRESSURE: [PRESSURE_MBAR, DEVICE_CLASS_PRESSURE],
|
||||
SENSOR_TYPE_ILLUMINANCE: [LIGHT_LUX, DEVICE_CLASS_ILLUMINANCE],
|
||||
SENSOR_TYPE_WETNESS: [PERCENTAGE, DEVICE_CLASS_HUMIDITY],
|
||||
SENSOR_TYPE_MOISTURE: [PRESSURE_CBAR, DEVICE_CLASS_PRESSURE],
|
||||
SENSOR_TYPE_COUNT: ["count", None],
|
||||
SENSOR_TYPE_VOLTAGE: [ELECTRIC_POTENTIAL_VOLT, DEVICE_CLASS_VOLTAGE],
|
||||
SENSOR_TYPE_CURRENT: [ELECTRIC_CURRENT_AMPERE, DEVICE_CLASS_CURRENT],
|
||||
SENSOR_TYPE_SENSED: [None, None],
|
||||
SWITCH_TYPE_LATCH: [None, None],
|
||||
SWITCH_TYPE_PIO: [None, None],
|
||||
}
|
||||
READ_MODE_BOOL = "bool"
|
||||
READ_MODE_FLOAT = "float"
|
||||
READ_MODE_INT = "int"
|
||||
|
||||
PLATFORMS = [
|
||||
BINARY_SENSOR_DOMAIN,
|
||||
|
@ -4,15 +4,6 @@ from __future__ import annotations
|
||||
from typing import TypedDict
|
||||
|
||||
|
||||
class DeviceComponentDescription(TypedDict, total=False):
|
||||
"""Device component description class."""
|
||||
|
||||
path: str
|
||||
name: str
|
||||
type: str
|
||||
default_disabled: bool
|
||||
|
||||
|
||||
class OWServerDeviceDescription(TypedDict):
|
||||
"""OWServer device description class."""
|
||||
|
||||
|
@ -1,22 +1,24 @@
|
||||
"""Support for 1-Wire entities."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from pyownet import protocol
|
||||
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity, EntityDescription
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from .const import (
|
||||
SENSOR_TYPE_COUNT,
|
||||
SENSOR_TYPE_SENSED,
|
||||
SENSOR_TYPES,
|
||||
SWITCH_TYPE_LATCH,
|
||||
SWITCH_TYPE_PIO,
|
||||
)
|
||||
from .model import DeviceComponentDescription
|
||||
from .const import READ_MODE_BOOL, READ_MODE_INT
|
||||
|
||||
|
||||
@dataclass
|
||||
class OneWireEntityDescription(EntityDescription):
|
||||
"""Class describing OneWire entities."""
|
||||
|
||||
read_mode: str | None = None
|
||||
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -24,57 +26,32 @@ _LOGGER = logging.getLogger(__name__)
|
||||
class OneWireBaseEntity(Entity):
|
||||
"""Implementation of a 1-Wire entity."""
|
||||
|
||||
entity_description: OneWireEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
device_file: str,
|
||||
entity_type: str,
|
||||
entity_name: str,
|
||||
description: OneWireEntityDescription,
|
||||
device_id: str,
|
||||
device_info: DeviceInfo,
|
||||
default_disabled: bool,
|
||||
unique_id: str,
|
||||
device_file: str,
|
||||
name: str,
|
||||
) -> None:
|
||||
"""Initialize the entity."""
|
||||
self._name = f"{name} {entity_name or entity_type.capitalize()}"
|
||||
self.entity_description = description
|
||||
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._entity_type = entity_type
|
||||
self._device_class = SENSOR_TYPES[entity_type][1]
|
||||
self._unit_of_measurement = SENSOR_TYPES[entity_type][0]
|
||||
self._device_info = device_info
|
||||
self._state: StateType = None
|
||||
self._value_raw: float | None = None
|
||||
self._default_disabled = default_disabled
|
||||
self._unique_id = unique_id
|
||||
|
||||
@property
|
||||
def name(self) -> str | None:
|
||||
"""Return the name of the entity."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def device_class(self) -> str | None:
|
||||
"""Return the class of this device."""
|
||||
return self._device_class
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict[str, Any] | None:
|
||||
"""Return the state attributes of the entity."""
|
||||
return {"device_file": self._device_file, "raw_value": self._value_raw}
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str | None:
|
||||
"""Return a unique ID."""
|
||||
return self._unique_id
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo | None:
|
||||
"""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
|
||||
return {
|
||||
"device_file": self._device_file,
|
||||
"raw_value": self._value_raw,
|
||||
}
|
||||
|
||||
|
||||
class OneWireProxyEntity(OneWireBaseEntity):
|
||||
@ -82,22 +59,20 @@ class OneWireProxyEntity(OneWireBaseEntity):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
description: OneWireEntityDescription,
|
||||
device_id: str,
|
||||
device_name: str,
|
||||
device_info: DeviceInfo,
|
||||
entity_path: str,
|
||||
entity_specs: DeviceComponentDescription,
|
||||
device_file: str,
|
||||
name: str,
|
||||
owproxy: protocol._Proxy,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(
|
||||
name=device_name,
|
||||
device_file=entity_path,
|
||||
entity_type=entity_specs["type"],
|
||||
entity_name=entity_specs["name"],
|
||||
description=description,
|
||||
device_id=device_id,
|
||||
device_info=device_info,
|
||||
default_disabled=entity_specs.get("default_disabled", False),
|
||||
unique_id=f"/{device_id}/{entity_specs['path']}",
|
||||
device_file=device_file,
|
||||
name=name,
|
||||
)
|
||||
self._owproxy = owproxy
|
||||
|
||||
@ -118,13 +93,9 @@ class OneWireProxyEntity(OneWireBaseEntity):
|
||||
_LOGGER.error("Owserver failure in read(), got: %s", exc)
|
||||
self._state = None
|
||||
else:
|
||||
if self._entity_type == SENSOR_TYPE_COUNT:
|
||||
if self.entity_description.read_mode == READ_MODE_INT:
|
||||
self._state = int(self._value_raw)
|
||||
elif self._entity_type in [
|
||||
SENSOR_TYPE_SENSED,
|
||||
SWITCH_TYPE_LATCH,
|
||||
SWITCH_TYPE_PIO,
|
||||
]:
|
||||
elif self.entity_description.read_mode == READ_MODE_BOOL:
|
||||
self._state = int(self._value_raw) == 1
|
||||
else:
|
||||
self._state = round(self._value_raw, 1)
|
||||
|
@ -2,6 +2,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import copy
|
||||
from dataclasses import dataclass
|
||||
import logging
|
||||
import os
|
||||
from types import MappingProxyType
|
||||
@ -9,7 +11,12 @@ from typing import Any
|
||||
|
||||
from pi1wire import InvalidCRCException, OneWireInterface, UnsupportResponseException
|
||||
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.components.sensor import (
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
STATE_CLASS_TOTAL_INCREASING,
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_IDENTIFIERS,
|
||||
@ -17,6 +24,18 @@ from homeassistant.const import (
|
||||
ATTR_MODEL,
|
||||
ATTR_NAME,
|
||||
CONF_TYPE,
|
||||
DEVICE_CLASS_CURRENT,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_ILLUMINANCE,
|
||||
DEVICE_CLASS_PRESSURE,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
DEVICE_CLASS_VOLTAGE,
|
||||
ELECTRIC_CURRENT_AMPERE,
|
||||
ELECTRIC_POTENTIAL_VOLT,
|
||||
LIGHT_LUX,
|
||||
PERCENTAGE,
|
||||
PRESSURE_MBAR,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
@ -29,122 +48,172 @@ from .const import (
|
||||
CONF_TYPE_OWSERVER,
|
||||
CONF_TYPE_SYSBUS,
|
||||
DOMAIN,
|
||||
SENSOR_TYPE_COUNT,
|
||||
SENSOR_TYPE_CURRENT,
|
||||
SENSOR_TYPE_HUMIDITY,
|
||||
SENSOR_TYPE_ILLUMINANCE,
|
||||
SENSOR_TYPE_MOISTURE,
|
||||
SENSOR_TYPE_PRESSURE,
|
||||
SENSOR_TYPE_TEMPERATURE,
|
||||
SENSOR_TYPE_VOLTAGE,
|
||||
SENSOR_TYPE_WETNESS,
|
||||
PRESSURE_CBAR,
|
||||
READ_MODE_FLOAT,
|
||||
READ_MODE_INT,
|
||||
)
|
||||
from .onewire_entities import (
|
||||
OneWireBaseEntity,
|
||||
OneWireEntityDescription,
|
||||
OneWireProxyEntity,
|
||||
)
|
||||
from .model import DeviceComponentDescription
|
||||
from .onewire_entities import OneWireBaseEntity, OneWireProxyEntity
|
||||
from .onewirehub import OneWireHub
|
||||
|
||||
|
||||
@dataclass
|
||||
class OneWireSensorEntityDescription(OneWireEntityDescription, SensorEntityDescription):
|
||||
"""Class describing OneWire sensor entities."""
|
||||
|
||||
|
||||
SIMPLE_TEMPERATURE_SENSOR_DESCRIPTION = OneWireSensorEntityDescription(
|
||||
key="temperature",
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEVICE_SENSORS: dict[str, list[DeviceComponentDescription]] = {
|
||||
# Family : { SensorType: owfs path }
|
||||
"10": [
|
||||
{"path": "temperature", "name": "Temperature", "type": SENSOR_TYPE_TEMPERATURE}
|
||||
],
|
||||
"12": [
|
||||
{
|
||||
"path": "TAI8570/temperature",
|
||||
"name": "Temperature",
|
||||
"type": SENSOR_TYPE_TEMPERATURE,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "TAI8570/pressure",
|
||||
"name": "Pressure",
|
||||
"type": SENSOR_TYPE_PRESSURE,
|
||||
"default_disabled": True,
|
||||
},
|
||||
],
|
||||
"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,
|
||||
"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": "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,
|
||||
},
|
||||
],
|
||||
"28": [
|
||||
{"path": "temperature", "name": "Temperature", "type": SENSOR_TYPE_TEMPERATURE}
|
||||
],
|
||||
"3B": [
|
||||
{"path": "temperature", "name": "Temperature", "type": SENSOR_TYPE_TEMPERATURE}
|
||||
],
|
||||
"42": [
|
||||
{"path": "temperature", "name": "Temperature", "type": SENSOR_TYPE_TEMPERATURE}
|
||||
],
|
||||
"1D": [
|
||||
{"path": "counter.A", "name": "Counter A", "type": SENSOR_TYPE_COUNT},
|
||||
{"path": "counter.B", "name": "Counter B", "type": SENSOR_TYPE_COUNT},
|
||||
],
|
||||
"EF": [], # "HobbyBoard": special
|
||||
"7E": [], # "EDS": special
|
||||
|
||||
DEVICE_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
||||
"10": (SIMPLE_TEMPERATURE_SENSOR_DESCRIPTION,),
|
||||
"12": (
|
||||
OneWireSensorEntityDescription(
|
||||
key="TAI8570/temperature",
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="TAI8570/pressure",
|
||||
device_class=DEVICE_CLASS_PRESSURE,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Pressure",
|
||||
native_unit_of_measurement=PRESSURE_MBAR,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
),
|
||||
"22": (SIMPLE_TEMPERATURE_SENSOR_DESCRIPTION,),
|
||||
"26": (
|
||||
SIMPLE_TEMPERATURE_SENSOR_DESCRIPTION,
|
||||
OneWireSensorEntityDescription(
|
||||
key="humidity",
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Humidity",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="HIH3600/humidity",
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Humidity HIH3600",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="HIH4000/humidity",
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Humidity HIH4000",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="HIH5030/humidity",
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Humidity HIH5030",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="HTM1735/humidity",
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Humidity HTM1735",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="B1-R1-A/pressure",
|
||||
device_class=DEVICE_CLASS_PRESSURE,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Pressure",
|
||||
native_unit_of_measurement=PRESSURE_MBAR,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="S3-R1-A/illuminance",
|
||||
device_class=DEVICE_CLASS_ILLUMINANCE,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Illuminance",
|
||||
native_unit_of_measurement=LIGHT_LUX,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="VAD",
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Voltage VAD",
|
||||
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="VDD",
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Voltage VDD",
|
||||
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="IAD",
|
||||
device_class=DEVICE_CLASS_CURRENT,
|
||||
entity_registry_enabled_default=False,
|
||||
name="Current",
|
||||
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
),
|
||||
"28": (SIMPLE_TEMPERATURE_SENSOR_DESCRIPTION,),
|
||||
"3B": (SIMPLE_TEMPERATURE_SENSOR_DESCRIPTION,),
|
||||
"42": (SIMPLE_TEMPERATURE_SENSOR_DESCRIPTION,),
|
||||
"1D": (
|
||||
OneWireSensorEntityDescription(
|
||||
key="counter.A",
|
||||
name="Counter A",
|
||||
native_unit_of_measurement="count",
|
||||
read_mode=READ_MODE_INT,
|
||||
state_class=STATE_CLASS_TOTAL_INCREASING,
|
||||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="counter.B",
|
||||
name="Counter B",
|
||||
native_unit_of_measurement="count",
|
||||
read_mode=READ_MODE_INT,
|
||||
state_class=STATE_CLASS_TOTAL_INCREASING,
|
||||
),
|
||||
),
|
||||
"EF": (), # "HobbyBoard": special
|
||||
"7E": (), # "EDS": special
|
||||
}
|
||||
|
||||
DEVICE_SUPPORT_SYSBUS = ["10", "22", "28", "3B", "42"]
|
||||
@ -153,85 +222,124 @@ DEVICE_SUPPORT_SYSBUS = ["10", "22", "28", "3B", "42"]
|
||||
# These can only be read by OWFS. Currently this driver only supports them
|
||||
# via owserver (network protocol)
|
||||
|
||||
HOBBYBOARD_EF: dict[str, list[DeviceComponentDescription]] = {
|
||||
"HobbyBoards_EF": [
|
||||
{
|
||||
"path": "humidity/humidity_corrected",
|
||||
"name": "Humidity",
|
||||
"type": SENSOR_TYPE_HUMIDITY,
|
||||
},
|
||||
{
|
||||
"path": "humidity/humidity_raw",
|
||||
"name": "Humidity Raw",
|
||||
"type": SENSOR_TYPE_HUMIDITY,
|
||||
},
|
||||
{
|
||||
"path": "humidity/temperature",
|
||||
"name": "Temperature",
|
||||
"type": SENSOR_TYPE_TEMPERATURE,
|
||||
},
|
||||
],
|
||||
"HB_MOISTURE_METER": [
|
||||
{
|
||||
"path": "moisture/sensor.0",
|
||||
"name": "Moisture 0",
|
||||
"type": SENSOR_TYPE_MOISTURE,
|
||||
},
|
||||
{
|
||||
"path": "moisture/sensor.1",
|
||||
"name": "Moisture 1",
|
||||
"type": SENSOR_TYPE_MOISTURE,
|
||||
},
|
||||
{
|
||||
"path": "moisture/sensor.2",
|
||||
"name": "Moisture 2",
|
||||
"type": SENSOR_TYPE_MOISTURE,
|
||||
},
|
||||
{
|
||||
"path": "moisture/sensor.3",
|
||||
"name": "Moisture 3",
|
||||
"type": SENSOR_TYPE_MOISTURE,
|
||||
},
|
||||
],
|
||||
HOBBYBOARD_EF: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
||||
"HobbyBoards_EF": (
|
||||
OneWireSensorEntityDescription(
|
||||
key="humidity/humidity_corrected",
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
name="Humidity",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="humidity/humidity_raw",
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
name="Humidity Raw",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="humidity/temperature",
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
),
|
||||
"HB_MOISTURE_METER": (
|
||||
OneWireSensorEntityDescription(
|
||||
key="moisture/sensor.0",
|
||||
device_class=DEVICE_CLASS_PRESSURE,
|
||||
name="Moisture 0",
|
||||
native_unit_of_measurement=PRESSURE_CBAR,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="moisture/sensor.1",
|
||||
device_class=DEVICE_CLASS_PRESSURE,
|
||||
name="Moisture 1",
|
||||
native_unit_of_measurement=PRESSURE_CBAR,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="moisture/sensor.2",
|
||||
device_class=DEVICE_CLASS_PRESSURE,
|
||||
name="Moisture 2",
|
||||
native_unit_of_measurement=PRESSURE_CBAR,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="moisture/sensor.3",
|
||||
device_class=DEVICE_CLASS_PRESSURE,
|
||||
name="Moisture 3",
|
||||
native_unit_of_measurement=PRESSURE_CBAR,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
),
|
||||
}
|
||||
|
||||
# 7E sensors are special sensors by Embedded Data Systems
|
||||
|
||||
EDS_SENSORS: dict[str, list[DeviceComponentDescription]] = {
|
||||
"EDS0066": [
|
||||
{
|
||||
"path": "EDS0066/temperature",
|
||||
"name": "Temperature",
|
||||
"type": SENSOR_TYPE_TEMPERATURE,
|
||||
},
|
||||
{
|
||||
"path": "EDS0066/pressure",
|
||||
"name": "Pressure",
|
||||
"type": SENSOR_TYPE_PRESSURE,
|
||||
},
|
||||
],
|
||||
"EDS0068": [
|
||||
{
|
||||
"path": "EDS0068/temperature",
|
||||
"name": "Temperature",
|
||||
"type": SENSOR_TYPE_TEMPERATURE,
|
||||
},
|
||||
{
|
||||
"path": "EDS0068/pressure",
|
||||
"name": "Pressure",
|
||||
"type": SENSOR_TYPE_PRESSURE,
|
||||
},
|
||||
{
|
||||
"path": "EDS0068/light",
|
||||
"name": "Illuminance",
|
||||
"type": SENSOR_TYPE_ILLUMINANCE,
|
||||
},
|
||||
{
|
||||
"path": "EDS0068/humidity",
|
||||
"name": "Humidity",
|
||||
"type": SENSOR_TYPE_HUMIDITY,
|
||||
},
|
||||
],
|
||||
EDS_SENSORS: dict[str, tuple[OneWireSensorEntityDescription, ...]] = {
|
||||
"EDS0066": (
|
||||
OneWireSensorEntityDescription(
|
||||
key="EDS0066/temperature",
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="EDS0066/pressure",
|
||||
device_class=DEVICE_CLASS_PRESSURE,
|
||||
name="Pressure",
|
||||
native_unit_of_measurement=PRESSURE_MBAR,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
),
|
||||
"EDS0068": (
|
||||
OneWireSensorEntityDescription(
|
||||
key="EDS0068/temperature",
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="EDS0068/pressure",
|
||||
device_class=DEVICE_CLASS_PRESSURE,
|
||||
name="Pressure",
|
||||
native_unit_of_measurement=PRESSURE_MBAR,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="EDS0068/light",
|
||||
device_class=DEVICE_CLASS_ILLUMINANCE,
|
||||
name="Illuminance",
|
||||
native_unit_of_measurement=LIGHT_LUX,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
OneWireSensorEntityDescription(
|
||||
key="EDS0068/humidity",
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
name="Humidity",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
read_mode=READ_MODE_FLOAT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
@ -259,12 +367,12 @@ async def async_setup_entry(
|
||||
|
||||
def get_entities(
|
||||
onewirehub: OneWireHub, config: MappingProxyType[str, Any]
|
||||
) -> list[OneWireBaseEntity]:
|
||||
) -> list[SensorEntity]:
|
||||
"""Get a list of entities."""
|
||||
if not onewirehub.devices:
|
||||
return []
|
||||
|
||||
entities: list[OneWireBaseEntity] = []
|
||||
entities: list[SensorEntity] = []
|
||||
device_names = {}
|
||||
if CONF_NAMES in config and isinstance(config[CONF_NAMES], dict):
|
||||
device_names = config[CONF_NAMES]
|
||||
@ -299,27 +407,30 @@ def get_entities(
|
||||
ATTR_MODEL: device_type,
|
||||
ATTR_NAME: device_id,
|
||||
}
|
||||
for entity_specs in get_sensor_types(device_sub_type)[family]:
|
||||
if entity_specs["type"] == SENSOR_TYPE_MOISTURE:
|
||||
s_id = entity_specs["path"].split(".")[1]
|
||||
for description in get_sensor_types(device_sub_type)[family]:
|
||||
if description.key.startswith("moisture/"):
|
||||
s_id = description.key.split(".")[1]
|
||||
is_leaf = int(
|
||||
onewirehub.owproxy.read(
|
||||
f"{device_path}moisture/is_leaf.{s_id}"
|
||||
).decode()
|
||||
)
|
||||
if is_leaf:
|
||||
entity_specs["type"] = SENSOR_TYPE_WETNESS
|
||||
entity_specs["name"] = f"Wetness {s_id}"
|
||||
entity_path = os.path.join(
|
||||
os.path.split(device_path)[0], entity_specs["path"]
|
||||
description = copy.deepcopy(description)
|
||||
description.device_class = DEVICE_CLASS_HUMIDITY
|
||||
description.native_unit_of_measurement = PERCENTAGE
|
||||
description.name = f"Wetness {s_id}"
|
||||
device_file = os.path.join(
|
||||
os.path.split(device["path"])[0], description.key
|
||||
)
|
||||
name = f"{device_names.get(device_id, device_id)} {description.name}"
|
||||
entities.append(
|
||||
OneWireProxySensor(
|
||||
description=description,
|
||||
device_id=device_id,
|
||||
device_name=device_names.get(device_id, device_id),
|
||||
device_file=device_file,
|
||||
device_info=device_info,
|
||||
entity_path=entity_path,
|
||||
entity_specs=entity_specs,
|
||||
name=name,
|
||||
owproxy=onewirehub.owproxy,
|
||||
)
|
||||
)
|
||||
@ -330,28 +441,32 @@ def get_entities(
|
||||
_LOGGER.debug("Initializing using SysBus %s", base_dir)
|
||||
for p1sensor in onewirehub.devices:
|
||||
family = p1sensor.mac_address[:2]
|
||||
sensor_id = f"{family}-{p1sensor.mac_address[2:]}"
|
||||
device_id = f"{family}-{p1sensor.mac_address[2:]}"
|
||||
if family not in DEVICE_SUPPORT_SYSBUS:
|
||||
_LOGGER.warning(
|
||||
"Ignoring unknown family (%s) of sensor found for device: %s",
|
||||
family,
|
||||
sensor_id,
|
||||
device_id,
|
||||
)
|
||||
continue
|
||||
|
||||
device_info = {
|
||||
ATTR_IDENTIFIERS: {(DOMAIN, sensor_id)},
|
||||
ATTR_IDENTIFIERS: {(DOMAIN, device_id)},
|
||||
ATTR_MANUFACTURER: "Maxim Integrated",
|
||||
ATTR_MODEL: family,
|
||||
ATTR_NAME: sensor_id,
|
||||
ATTR_NAME: device_id,
|
||||
}
|
||||
device_file = f"/sys/bus/w1/devices/{sensor_id}/w1_slave"
|
||||
description = SIMPLE_TEMPERATURE_SENSOR_DESCRIPTION
|
||||
device_file = f"/sys/bus/w1/devices/{device_id}/w1_slave"
|
||||
name = f"{device_names.get(device_id, device_id)} {description.name}"
|
||||
entities.append(
|
||||
OneWireDirectSensor(
|
||||
device_names.get(sensor_id, sensor_id),
|
||||
device_file,
|
||||
device_info,
|
||||
p1sensor,
|
||||
description=description,
|
||||
device_id=device_id,
|
||||
device_file=device_file,
|
||||
device_info=device_info,
|
||||
name=name,
|
||||
owsensor=p1sensor,
|
||||
)
|
||||
)
|
||||
if not entities:
|
||||
@ -367,15 +482,14 @@ def get_entities(
|
||||
class OneWireSensor(OneWireBaseEntity, SensorEntity):
|
||||
"""Mixin for sensor specific attributes."""
|
||||
|
||||
@property
|
||||
def native_unit_of_measurement(self) -> str | None:
|
||||
"""Return the unit the value is expressed in."""
|
||||
return self._unit_of_measurement
|
||||
entity_description: OneWireSensorEntityDescription
|
||||
|
||||
|
||||
class OneWireProxySensor(OneWireProxyEntity, OneWireSensor):
|
||||
"""Implementation of a 1-Wire sensor connected through owserver."""
|
||||
|
||||
entity_description: OneWireSensorEntityDescription
|
||||
|
||||
@property
|
||||
def native_value(self) -> StateType:
|
||||
"""Return the state of the entity."""
|
||||
@ -387,21 +501,22 @@ class OneWireDirectSensor(OneWireSensor):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
device_file: str,
|
||||
description: OneWireSensorEntityDescription,
|
||||
device_id: str,
|
||||
device_info: DeviceInfo,
|
||||
device_file: str,
|
||||
name: str,
|
||||
owsensor: OneWireInterface,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(
|
||||
name,
|
||||
device_file,
|
||||
"temperature",
|
||||
"Temperature",
|
||||
device_info,
|
||||
False,
|
||||
device_file,
|
||||
description=description,
|
||||
device_id=device_id,
|
||||
device_info=device_info,
|
||||
device_file=device_file,
|
||||
name=name,
|
||||
)
|
||||
self._attr_unique_id = device_file
|
||||
self._owsensor = owsensor
|
||||
|
||||
@property
|
||||
@ -439,5 +554,9 @@ class OneWireDirectSensor(OneWireSensor):
|
||||
InvalidCRCException,
|
||||
UnsupportResponseException,
|
||||
) as ex:
|
||||
_LOGGER.warning("Cannot read from sensor %s: %s", self._device_file, ex)
|
||||
_LOGGER.warning(
|
||||
"Cannot read from sensor %s: %s",
|
||||
self._device_file,
|
||||
ex,
|
||||
)
|
||||
self._state = None
|
||||
|
@ -1,11 +1,12 @@
|
||||
"""Support for 1-Wire environment switches."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
import logging
|
||||
import os
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_IDENTIFIERS,
|
||||
@ -18,145 +19,149 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import CONF_TYPE_OWSERVER, DOMAIN, SWITCH_TYPE_LATCH, SWITCH_TYPE_PIO
|
||||
from .model import DeviceComponentDescription
|
||||
from .onewire_entities import OneWireBaseEntity, OneWireProxyEntity
|
||||
from .const import CONF_TYPE_OWSERVER, DOMAIN, READ_MODE_BOOL
|
||||
from .onewire_entities import OneWireEntityDescription, OneWireProxyEntity
|
||||
from .onewirehub import OneWireHub
|
||||
|
||||
DEVICE_SWITCHES: dict[str, list[DeviceComponentDescription]] = {
|
||||
# Family : { owfs path }
|
||||
"05": [
|
||||
{
|
||||
"path": "PIO",
|
||||
"name": "PIO",
|
||||
"type": SWITCH_TYPE_PIO,
|
||||
"default_disabled": True,
|
||||
},
|
||||
],
|
||||
"12": [
|
||||
{
|
||||
"path": "PIO.A",
|
||||
"name": "PIO A",
|
||||
"type": SWITCH_TYPE_PIO,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "PIO.B",
|
||||
"name": "PIO B",
|
||||
"type": SWITCH_TYPE_PIO,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "latch.A",
|
||||
"name": "Latch A",
|
||||
"type": SWITCH_TYPE_LATCH,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "latch.B",
|
||||
"name": "Latch B",
|
||||
"type": SWITCH_TYPE_LATCH,
|
||||
"default_disabled": True,
|
||||
},
|
||||
],
|
||||
"29": [
|
||||
{
|
||||
"path": "PIO.0",
|
||||
"name": "PIO 0",
|
||||
"type": SWITCH_TYPE_PIO,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "PIO.1",
|
||||
"name": "PIO 1",
|
||||
"type": SWITCH_TYPE_PIO,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "PIO.2",
|
||||
"name": "PIO 2",
|
||||
"type": SWITCH_TYPE_PIO,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "PIO.3",
|
||||
"name": "PIO 3",
|
||||
"type": SWITCH_TYPE_PIO,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "PIO.4",
|
||||
"name": "PIO 4",
|
||||
"type": SWITCH_TYPE_PIO,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "PIO.5",
|
||||
"name": "PIO 5",
|
||||
"type": SWITCH_TYPE_PIO,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "PIO.6",
|
||||
"name": "PIO 6",
|
||||
"type": SWITCH_TYPE_PIO,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "PIO.7",
|
||||
"name": "PIO 7",
|
||||
"type": SWITCH_TYPE_PIO,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "latch.0",
|
||||
"name": "Latch 0",
|
||||
"type": SWITCH_TYPE_LATCH,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "latch.1",
|
||||
"name": "Latch 1",
|
||||
"type": SWITCH_TYPE_LATCH,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "latch.2",
|
||||
"name": "Latch 2",
|
||||
"type": SWITCH_TYPE_LATCH,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "latch.3",
|
||||
"name": "Latch 3",
|
||||
"type": SWITCH_TYPE_LATCH,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "latch.4",
|
||||
"name": "Latch 4",
|
||||
"type": SWITCH_TYPE_LATCH,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "latch.5",
|
||||
"name": "Latch 5",
|
||||
"type": SWITCH_TYPE_LATCH,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "latch.6",
|
||||
"name": "Latch 6",
|
||||
"type": SWITCH_TYPE_LATCH,
|
||||
"default_disabled": True,
|
||||
},
|
||||
{
|
||||
"path": "latch.7",
|
||||
"name": "Latch 7",
|
||||
"type": SWITCH_TYPE_LATCH,
|
||||
"default_disabled": True,
|
||||
},
|
||||
],
|
||||
|
||||
@dataclass
|
||||
class OneWireSwitchEntityDescription(OneWireEntityDescription, SwitchEntityDescription):
|
||||
"""Class describing OneWire switch entities."""
|
||||
|
||||
|
||||
DEVICE_SWITCHES: dict[str, tuple[OneWireEntityDescription, ...]] = {
|
||||
"05": (
|
||||
OneWireSwitchEntityDescription(
|
||||
key="PIO",
|
||||
entity_registry_enabled_default=False,
|
||||
name="PIO",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
),
|
||||
"12": (
|
||||
OneWireSwitchEntityDescription(
|
||||
key="PIO.A",
|
||||
entity_registry_enabled_default=False,
|
||||
name="PIO A",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireSwitchEntityDescription(
|
||||
key="PIO.B",
|
||||
entity_registry_enabled_default=False,
|
||||
name="PIO B",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireSwitchEntityDescription(
|
||||
key="latch.A",
|
||||
entity_registry_enabled_default=False,
|
||||
name="Latch A",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireSwitchEntityDescription(
|
||||
key="latch.B",
|
||||
entity_registry_enabled_default=False,
|
||||
name="Latch B",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
),
|
||||
"29": (
|
||||
OneWireSwitchEntityDescription(
|
||||
key="PIO.0",
|
||||
entity_registry_enabled_default=False,
|
||||
name="PIO 0",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireSwitchEntityDescription(
|
||||
key="PIO.1",
|
||||
entity_registry_enabled_default=False,
|
||||
name="PIO 1",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireSwitchEntityDescription(
|
||||
key="PIO.2",
|
||||
entity_registry_enabled_default=False,
|
||||
name="PIO 2",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireSwitchEntityDescription(
|
||||
key="PIO.3",
|
||||
entity_registry_enabled_default=False,
|
||||
name="PIO 3",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireSwitchEntityDescription(
|
||||
key="PIO.4",
|
||||
entity_registry_enabled_default=False,
|
||||
name="PIO 4",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireSwitchEntityDescription(
|
||||
key="PIO.5",
|
||||
entity_registry_enabled_default=False,
|
||||
name="PIO 5",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireSwitchEntityDescription(
|
||||
key="PIO.6",
|
||||
entity_registry_enabled_default=False,
|
||||
name="PIO 6",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireSwitchEntityDescription(
|
||||
key="PIO.7",
|
||||
entity_registry_enabled_default=False,
|
||||
name="PIO 7",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireSwitchEntityDescription(
|
||||
key="latch.0",
|
||||
entity_registry_enabled_default=False,
|
||||
name="Latch 0",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireSwitchEntityDescription(
|
||||
key="latch.1",
|
||||
entity_registry_enabled_default=False,
|
||||
name="Latch 1",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireSwitchEntityDescription(
|
||||
key="latch.2",
|
||||
entity_registry_enabled_default=False,
|
||||
name="Latch 2",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireSwitchEntityDescription(
|
||||
key="latch.3",
|
||||
entity_registry_enabled_default=False,
|
||||
name="Latch 3",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireSwitchEntityDescription(
|
||||
key="latch.4",
|
||||
entity_registry_enabled_default=False,
|
||||
name="Latch 4",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireSwitchEntityDescription(
|
||||
key="latch.5",
|
||||
entity_registry_enabled_default=False,
|
||||
name="Latch 5",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireSwitchEntityDescription(
|
||||
key="latch.6",
|
||||
entity_registry_enabled_default=False,
|
||||
name="Latch 6",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
OneWireSwitchEntityDescription(
|
||||
key="latch.7",
|
||||
entity_registry_enabled_default=False,
|
||||
name="Latch 7",
|
||||
read_mode=READ_MODE_BOOL,
|
||||
),
|
||||
),
|
||||
}
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
@ -176,12 +181,12 @@ async def async_setup_entry(
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
||||
def get_entities(onewirehub: OneWireHub) -> list[OneWireBaseEntity]:
|
||||
def get_entities(onewirehub: OneWireHub) -> list[SwitchEntity]:
|
||||
"""Get a list of entities."""
|
||||
if not onewirehub.devices:
|
||||
return []
|
||||
|
||||
entities: list[OneWireBaseEntity] = []
|
||||
entities: list[SwitchEntity] = []
|
||||
|
||||
for device in onewirehub.devices:
|
||||
family = device["family"]
|
||||
@ -197,17 +202,18 @@ def get_entities(onewirehub: OneWireHub) -> list[OneWireBaseEntity]:
|
||||
ATTR_MODEL: device_type,
|
||||
ATTR_NAME: device_id,
|
||||
}
|
||||
for entity_specs in DEVICE_SWITCHES[family]:
|
||||
entity_path = os.path.join(
|
||||
os.path.split(device["path"])[0], entity_specs["path"]
|
||||
for description in DEVICE_SWITCHES[family]:
|
||||
device_file = os.path.join(
|
||||
os.path.split(device["path"])[0], description.key
|
||||
)
|
||||
name = f"{device_id} {description.name}"
|
||||
entities.append(
|
||||
OneWireProxySwitch(
|
||||
description=description,
|
||||
device_id=device_id,
|
||||
device_name=device_id,
|
||||
device_file=device_file,
|
||||
device_info=device_info,
|
||||
entity_path=entity_path,
|
||||
entity_specs=entity_specs,
|
||||
name=name,
|
||||
owproxy=onewirehub.owproxy,
|
||||
)
|
||||
)
|
||||
@ -218,6 +224,8 @@ def get_entities(onewirehub: OneWireHub) -> list[OneWireBaseEntity]:
|
||||
class OneWireProxySwitch(OneWireProxyEntity, SwitchEntity):
|
||||
"""Implementation of a 1-Wire switch."""
|
||||
|
||||
entity_description: OneWireSwitchEntityDescription
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if sensor is on."""
|
||||
|
@ -5,13 +5,20 @@ from pyownet.protocol import Error as ProtocolError
|
||||
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
from homeassistant.components.onewire.const import DOMAIN, PRESSURE_CBAR
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.components.sensor import (
|
||||
ATTR_STATE_CLASS,
|
||||
DOMAIN as SENSOR_DOMAIN,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
STATE_CLASS_TOTAL_INCREASING,
|
||||
)
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||
from homeassistant.const import (
|
||||
ATTR_DEVICE_CLASS,
|
||||
ATTR_IDENTIFIERS,
|
||||
ATTR_MANUFACTURER,
|
||||
ATTR_MODEL,
|
||||
ATTR_NAME,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
DEVICE_CLASS_CURRENT,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_ILLUMINANCE,
|
||||
@ -53,8 +60,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/05.111111111111/PIO",
|
||||
"injected_value": b" 1",
|
||||
"result": STATE_ON,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
],
|
||||
@ -75,8 +82,9 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/10.111111111111/temperature",
|
||||
"injected_value": b" 25.123",
|
||||
"result": "25.1",
|
||||
"unit": TEMP_CELSIUS,
|
||||
"class": DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -96,8 +104,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/12.111111111111/sensed.A",
|
||||
"injected_value": b" 1",
|
||||
"result": STATE_ON,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -105,8 +113,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/12.111111111111/sensed.B",
|
||||
"injected_value": b" 0",
|
||||
"result": STATE_OFF,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
],
|
||||
@ -116,18 +124,20 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/12.111111111111/TAI8570/temperature",
|
||||
"injected_value": b" 25.123",
|
||||
"result": "25.1",
|
||||
"unit": TEMP_CELSIUS,
|
||||
"class": DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
|
||||
"disabled": True,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.12_111111111111_pressure",
|
||||
"unique_id": "/12.111111111111/TAI8570/pressure",
|
||||
"injected_value": b" 1025.123",
|
||||
"result": "1025.1",
|
||||
"unit": PRESSURE_MBAR,
|
||||
"class": DEVICE_CLASS_PRESSURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: PRESSURE_MBAR,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_PRESSURE,
|
||||
"disabled": True,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
],
|
||||
SWITCH_DOMAIN: [
|
||||
@ -136,8 +146,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/12.111111111111/PIO.A",
|
||||
"injected_value": b" 1",
|
||||
"result": STATE_ON,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -145,8 +155,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/12.111111111111/PIO.B",
|
||||
"injected_value": b" 0",
|
||||
"result": STATE_OFF,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -154,8 +164,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/12.111111111111/latch.A",
|
||||
"injected_value": b" 1",
|
||||
"result": STATE_ON,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -163,8 +173,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/12.111111111111/latch.B",
|
||||
"injected_value": b" 0",
|
||||
"result": STATE_OFF,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
],
|
||||
@ -185,16 +195,18 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/1D.111111111111/counter.A",
|
||||
"injected_value": b" 251123",
|
||||
"result": "251123",
|
||||
"unit": "count",
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: "count",
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_TOTAL_INCREASING,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.1d_111111111111_counter_b",
|
||||
"unique_id": "/1D.111111111111/counter.B",
|
||||
"injected_value": b" 248125",
|
||||
"result": "248125",
|
||||
"unit": "count",
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: "count",
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_TOTAL_INCREASING,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -228,8 +240,9 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/1D.111111111111/counter.A",
|
||||
"injected_value": b" 251123",
|
||||
"result": "251123",
|
||||
"unit": "count",
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: "count",
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_TOTAL_INCREASING,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.1d_111111111111_counter_b",
|
||||
@ -237,8 +250,9 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/1D.111111111111/counter.B",
|
||||
"injected_value": b" 248125",
|
||||
"result": "248125",
|
||||
"unit": "count",
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: "count",
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_TOTAL_INCREASING,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -261,8 +275,9 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/22.111111111111/temperature",
|
||||
"injected_value": ProtocolError,
|
||||
"result": "unknown",
|
||||
"unit": TEMP_CELSIUS,
|
||||
"class": DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -282,98 +297,109 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/26.111111111111/temperature",
|
||||
"injected_value": b" 25.123",
|
||||
"result": "25.1",
|
||||
"unit": TEMP_CELSIUS,
|
||||
"class": DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_humidity",
|
||||
"unique_id": "/26.111111111111/humidity",
|
||||
"injected_value": b" 72.7563",
|
||||
"result": "72.8",
|
||||
"unit": PERCENTAGE,
|
||||
"class": DEVICE_CLASS_HUMIDITY,
|
||||
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY,
|
||||
"disabled": True,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_humidity_hih3600",
|
||||
"unique_id": "/26.111111111111/HIH3600/humidity",
|
||||
"injected_value": b" 73.7563",
|
||||
"result": "73.8",
|
||||
"unit": PERCENTAGE,
|
||||
"class": DEVICE_CLASS_HUMIDITY,
|
||||
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY,
|
||||
"disabled": True,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_humidity_hih4000",
|
||||
"unique_id": "/26.111111111111/HIH4000/humidity",
|
||||
"injected_value": b" 74.7563",
|
||||
"result": "74.8",
|
||||
"unit": PERCENTAGE,
|
||||
"class": DEVICE_CLASS_HUMIDITY,
|
||||
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY,
|
||||
"disabled": True,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_humidity_hih5030",
|
||||
"unique_id": "/26.111111111111/HIH5030/humidity",
|
||||
"injected_value": b" 75.7563",
|
||||
"result": "75.8",
|
||||
"unit": PERCENTAGE,
|
||||
"class": DEVICE_CLASS_HUMIDITY,
|
||||
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY,
|
||||
"disabled": True,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_humidity_htm1735",
|
||||
"unique_id": "/26.111111111111/HTM1735/humidity",
|
||||
"injected_value": ProtocolError,
|
||||
"result": "unknown",
|
||||
"unit": PERCENTAGE,
|
||||
"class": DEVICE_CLASS_HUMIDITY,
|
||||
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY,
|
||||
"disabled": True,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_pressure",
|
||||
"unique_id": "/26.111111111111/B1-R1-A/pressure",
|
||||
"injected_value": b" 969.265",
|
||||
"result": "969.3",
|
||||
"unit": PRESSURE_MBAR,
|
||||
"class": DEVICE_CLASS_PRESSURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: PRESSURE_MBAR,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_PRESSURE,
|
||||
"disabled": True,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_illuminance",
|
||||
"unique_id": "/26.111111111111/S3-R1-A/illuminance",
|
||||
"injected_value": b" 65.8839",
|
||||
"result": "65.9",
|
||||
"unit": LIGHT_LUX,
|
||||
"class": DEVICE_CLASS_ILLUMINANCE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: LIGHT_LUX,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_ILLUMINANCE,
|
||||
"disabled": True,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_voltage_vad",
|
||||
"unique_id": "/26.111111111111/VAD",
|
||||
"injected_value": b" 2.97",
|
||||
"result": "3.0",
|
||||
"unit": ELECTRIC_POTENTIAL_VOLT,
|
||||
"class": DEVICE_CLASS_VOLTAGE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: ELECTRIC_POTENTIAL_VOLT,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_VOLTAGE,
|
||||
"disabled": True,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_voltage_vdd",
|
||||
"unique_id": "/26.111111111111/VDD",
|
||||
"injected_value": b" 4.74",
|
||||
"result": "4.7",
|
||||
"unit": ELECTRIC_POTENTIAL_VOLT,
|
||||
"class": DEVICE_CLASS_VOLTAGE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: ELECTRIC_POTENTIAL_VOLT,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_VOLTAGE,
|
||||
"disabled": True,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.26_111111111111_current",
|
||||
"unique_id": "/26.111111111111/IAD",
|
||||
"injected_value": b" 1",
|
||||
"result": "1.0",
|
||||
"unit": ELECTRIC_CURRENT_AMPERE,
|
||||
"class": DEVICE_CLASS_CURRENT,
|
||||
ATTR_UNIT_OF_MEASUREMENT: ELECTRIC_CURRENT_AMPERE,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_CURRENT,
|
||||
"disabled": True,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -393,8 +419,9 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/28.111111111111/temperature",
|
||||
"injected_value": b" 26.984",
|
||||
"result": "27.0",
|
||||
"unit": TEMP_CELSIUS,
|
||||
"class": DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -414,8 +441,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/sensed.0",
|
||||
"injected_value": b" 1",
|
||||
"result": STATE_ON,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -423,8 +450,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/sensed.1",
|
||||
"injected_value": b" 0",
|
||||
"result": STATE_OFF,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -432,8 +459,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/sensed.2",
|
||||
"injected_value": b" 0",
|
||||
"result": STATE_OFF,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -441,8 +468,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/sensed.3",
|
||||
"injected_value": b" 0",
|
||||
"result": STATE_OFF,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -450,8 +477,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/sensed.4",
|
||||
"injected_value": b" 0",
|
||||
"result": STATE_OFF,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -459,8 +486,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/sensed.5",
|
||||
"injected_value": b" 0",
|
||||
"result": STATE_OFF,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -468,8 +495,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/sensed.6",
|
||||
"injected_value": b" 0",
|
||||
"result": STATE_OFF,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -477,8 +504,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/sensed.7",
|
||||
"injected_value": b" 0",
|
||||
"result": STATE_OFF,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
],
|
||||
@ -488,8 +515,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/PIO.0",
|
||||
"injected_value": b" 1",
|
||||
"result": STATE_ON,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -497,8 +524,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/PIO.1",
|
||||
"injected_value": b" 0",
|
||||
"result": STATE_OFF,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -506,8 +533,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/PIO.2",
|
||||
"injected_value": b" 1",
|
||||
"result": STATE_ON,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -515,8 +542,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/PIO.3",
|
||||
"injected_value": b" 0",
|
||||
"result": STATE_OFF,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -524,8 +551,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/PIO.4",
|
||||
"injected_value": b" 1",
|
||||
"result": STATE_ON,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -533,8 +560,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/PIO.5",
|
||||
"injected_value": b" 0",
|
||||
"result": STATE_OFF,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -542,8 +569,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/PIO.6",
|
||||
"injected_value": b" 1",
|
||||
"result": STATE_ON,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -551,8 +578,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/PIO.7",
|
||||
"injected_value": b" 0",
|
||||
"result": STATE_OFF,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -560,8 +587,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/latch.0",
|
||||
"injected_value": b" 1",
|
||||
"result": STATE_ON,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -569,8 +596,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/latch.1",
|
||||
"injected_value": b" 0",
|
||||
"result": STATE_OFF,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -578,8 +605,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/latch.2",
|
||||
"injected_value": b" 1",
|
||||
"result": STATE_ON,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -587,8 +614,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/latch.3",
|
||||
"injected_value": b" 0",
|
||||
"result": STATE_OFF,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -596,8 +623,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/latch.4",
|
||||
"injected_value": b" 1",
|
||||
"result": STATE_ON,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -605,8 +632,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/latch.5",
|
||||
"injected_value": b" 0",
|
||||
"result": STATE_OFF,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -614,8 +641,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/latch.6",
|
||||
"injected_value": b" 1",
|
||||
"result": STATE_ON,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
{
|
||||
@ -623,8 +650,8 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/29.111111111111/latch.7",
|
||||
"injected_value": b" 0",
|
||||
"result": STATE_OFF,
|
||||
"unit": None,
|
||||
"class": None,
|
||||
ATTR_UNIT_OF_MEASUREMENT: None,
|
||||
ATTR_DEVICE_CLASS: None,
|
||||
"disabled": True,
|
||||
},
|
||||
],
|
||||
@ -645,8 +672,9 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/3B.111111111111/temperature",
|
||||
"injected_value": b" 28.243",
|
||||
"result": "28.2",
|
||||
"unit": TEMP_CELSIUS,
|
||||
"class": DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -666,8 +694,9 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/42.111111111111/temperature",
|
||||
"injected_value": b" 29.123",
|
||||
"result": "29.1",
|
||||
"unit": TEMP_CELSIUS,
|
||||
"class": DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -687,24 +716,27 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/EF.111111111111/humidity/humidity_corrected",
|
||||
"injected_value": b" 67.745",
|
||||
"result": "67.7",
|
||||
"unit": PERCENTAGE,
|
||||
"class": DEVICE_CLASS_HUMIDITY,
|
||||
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.ef_111111111111_humidity_raw",
|
||||
"unique_id": "/EF.111111111111/humidity/humidity_raw",
|
||||
"injected_value": b" 65.541",
|
||||
"result": "65.5",
|
||||
"unit": PERCENTAGE,
|
||||
"class": DEVICE_CLASS_HUMIDITY,
|
||||
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.ef_111111111111_temperature",
|
||||
"unique_id": "/EF.111111111111/humidity/temperature",
|
||||
"injected_value": b" 25.123",
|
||||
"result": "25.1",
|
||||
"unit": TEMP_CELSIUS,
|
||||
"class": DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -728,32 +760,36 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/EF.111111111112/moisture/sensor.0",
|
||||
"injected_value": b" 41.745",
|
||||
"result": "41.7",
|
||||
"unit": PERCENTAGE,
|
||||
"class": DEVICE_CLASS_HUMIDITY,
|
||||
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.ef_111111111112_wetness_1",
|
||||
"unique_id": "/EF.111111111112/moisture/sensor.1",
|
||||
"injected_value": b" 42.541",
|
||||
"result": "42.5",
|
||||
"unit": PERCENTAGE,
|
||||
"class": DEVICE_CLASS_HUMIDITY,
|
||||
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.ef_111111111112_moisture_2",
|
||||
"unique_id": "/EF.111111111112/moisture/sensor.2",
|
||||
"injected_value": b" 43.123",
|
||||
"result": "43.1",
|
||||
"unit": PRESSURE_CBAR,
|
||||
"class": DEVICE_CLASS_PRESSURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: PRESSURE_CBAR,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_PRESSURE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.ef_111111111112_moisture_3",
|
||||
"unique_id": "/EF.111111111112/moisture/sensor.3",
|
||||
"injected_value": b" 44.123",
|
||||
"result": "44.1",
|
||||
"unit": PRESSURE_CBAR,
|
||||
"class": DEVICE_CLASS_PRESSURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: PRESSURE_CBAR,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_PRESSURE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -774,32 +810,36 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/7E.111111111111/EDS0068/temperature",
|
||||
"injected_value": b" 13.9375",
|
||||
"result": "13.9",
|
||||
"unit": TEMP_CELSIUS,
|
||||
"class": DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.7e_111111111111_pressure",
|
||||
"unique_id": "/7E.111111111111/EDS0068/pressure",
|
||||
"injected_value": b" 1012.21",
|
||||
"result": "1012.2",
|
||||
"unit": PRESSURE_MBAR,
|
||||
"class": DEVICE_CLASS_PRESSURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: PRESSURE_MBAR,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_PRESSURE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.7e_111111111111_illuminance",
|
||||
"unique_id": "/7E.111111111111/EDS0068/light",
|
||||
"injected_value": b" 65.8839",
|
||||
"result": "65.9",
|
||||
"unit": LIGHT_LUX,
|
||||
"class": DEVICE_CLASS_ILLUMINANCE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: LIGHT_LUX,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_ILLUMINANCE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.7e_111111111111_humidity",
|
||||
"unique_id": "/7E.111111111111/EDS0068/humidity",
|
||||
"injected_value": b" 41.375",
|
||||
"result": "41.4",
|
||||
"unit": PERCENTAGE,
|
||||
"class": DEVICE_CLASS_HUMIDITY,
|
||||
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -820,16 +860,18 @@ MOCK_OWPROXY_DEVICES = {
|
||||
"unique_id": "/7E.222222222222/EDS0066/temperature",
|
||||
"injected_value": b" 13.9375",
|
||||
"result": "13.9",
|
||||
"unit": TEMP_CELSIUS,
|
||||
"class": DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
{
|
||||
"entity_id": "sensor.7e_222222222222_pressure",
|
||||
"unique_id": "/7E.222222222222/EDS0066/pressure",
|
||||
"injected_value": b" 1012.21",
|
||||
"result": "1012.2",
|
||||
"unit": PRESSURE_MBAR,
|
||||
"class": DEVICE_CLASS_PRESSURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: PRESSURE_MBAR,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_PRESSURE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -850,8 +892,9 @@ MOCK_SYSBUS_DEVICES = {
|
||||
"unique_id": "/sys/bus/w1/devices/10-111111111111/w1_slave",
|
||||
"injected_value": 25.123,
|
||||
"result": "25.1",
|
||||
"unit": TEMP_CELSIUS,
|
||||
"class": DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -870,8 +913,9 @@ MOCK_SYSBUS_DEVICES = {
|
||||
"unique_id": "/sys/bus/w1/devices/22-111111111111/w1_slave",
|
||||
"injected_value": FileNotFoundError,
|
||||
"result": "unknown",
|
||||
"unit": TEMP_CELSIUS,
|
||||
"class": DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -889,8 +933,9 @@ MOCK_SYSBUS_DEVICES = {
|
||||
"unique_id": "/sys/bus/w1/devices/28-111111111111/w1_slave",
|
||||
"injected_value": InvalidCRCException,
|
||||
"result": "unknown",
|
||||
"unit": TEMP_CELSIUS,
|
||||
"class": DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -908,8 +953,9 @@ MOCK_SYSBUS_DEVICES = {
|
||||
"unique_id": "/sys/bus/w1/devices/3B-111111111111/w1_slave",
|
||||
"injected_value": 29.993,
|
||||
"result": "30.0",
|
||||
"unit": TEMP_CELSIUS,
|
||||
"class": DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -926,8 +972,9 @@ MOCK_SYSBUS_DEVICES = {
|
||||
"unique_id": "/sys/bus/w1/devices/42-111111111111/w1_slave",
|
||||
"injected_value": UnsupportResponseException,
|
||||
"result": "unknown",
|
||||
"unit": TEMP_CELSIUS,
|
||||
"class": DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -944,8 +991,9 @@ MOCK_SYSBUS_DEVICES = {
|
||||
"unique_id": "/sys/bus/w1/devices/42-111111111112/w1_slave",
|
||||
"injected_value": [UnsupportResponseException] * 9 + [27.993],
|
||||
"result": "28.0",
|
||||
"unit": TEMP_CELSIUS,
|
||||
"class": DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -962,8 +1010,9 @@ MOCK_SYSBUS_DEVICES = {
|
||||
"unique_id": "/sys/bus/w1/devices/42-111111111113/w1_slave",
|
||||
"injected_value": [UnsupportResponseException] * 10 + [27.993],
|
||||
"result": "unknown",
|
||||
"unit": TEMP_CELSIUS,
|
||||
"class": DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
|
||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -38,7 +38,7 @@ async def test_owserver_binary_sensor(owproxy, hass, device_id):
|
||||
# Force enable binary sensors
|
||||
patch_device_binary_sensors = copy.deepcopy(DEVICE_BINARY_SENSORS)
|
||||
for item in patch_device_binary_sensors[device_id[0:2]]:
|
||||
item["default_disabled"] = False
|
||||
item.entity_registry_enabled_default = True
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.onewire.PLATFORMS", [BINARY_SENSOR_DOMAIN]
|
||||
|
@ -9,8 +9,14 @@ from homeassistant.components.onewire.const import (
|
||||
DOMAIN,
|
||||
PLATFORMS,
|
||||
)
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.const import ATTR_MANUFACTURER, ATTR_MODEL, ATTR_NAME
|
||||
from homeassistant.components.sensor import ATTR_STATE_CLASS, DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.const import (
|
||||
ATTR_DEVICE_CLASS,
|
||||
ATTR_MANUFACTURER,
|
||||
ATTR_MODEL,
|
||||
ATTR_NAME,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import (
|
||||
@ -116,14 +122,11 @@ async def test_sensors_on_owserver_coupler(owproxy, hass, device_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"]
|
||||
assert registry_entry.device_class == expected_sensor["class"]
|
||||
assert registry_entry.disabled == expected_sensor.get("disabled", False)
|
||||
state = hass.states.get(entity_id)
|
||||
if registry_entry.disabled:
|
||||
assert state is None
|
||||
else:
|
||||
assert state.state == expected_sensor["result"]
|
||||
assert state.state == expected_sensor["result"]
|
||||
for attr in (ATTR_DEVICE_CLASS, ATTR_STATE_CLASS, ATTR_UNIT_OF_MEASUREMENT):
|
||||
assert state.attributes.get(attr) == expected_sensor[attr]
|
||||
assert state.attributes["device_file"] == expected_sensor["device_file"]
|
||||
|
||||
|
||||
@ -165,14 +168,14 @@ async def test_owserver_setup_valid_device(owproxy, hass, device_id, platform):
|
||||
registry_entry = entity_registry.entities.get(entity_id)
|
||||
assert registry_entry is not None
|
||||
assert registry_entry.unique_id == expected_entity["unique_id"]
|
||||
assert registry_entry.unit_of_measurement == expected_entity["unit"]
|
||||
assert registry_entry.device_class == expected_entity["class"]
|
||||
assert registry_entry.disabled == expected_entity.get("disabled", False)
|
||||
state = hass.states.get(entity_id)
|
||||
if registry_entry.disabled:
|
||||
assert state is None
|
||||
else:
|
||||
assert state.state == expected_entity["result"]
|
||||
for attr in (ATTR_DEVICE_CLASS, ATTR_STATE_CLASS, ATTR_UNIT_OF_MEASUREMENT):
|
||||
assert state.attributes.get(attr) == expected_entity[attr]
|
||||
assert state.attributes["device_file"] == expected_entity.get(
|
||||
"device_file", registry_entry.unique_id
|
||||
)
|
||||
@ -216,7 +219,7 @@ async def test_onewiredirect_setup_valid_device(hass, device_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"]
|
||||
assert registry_entry.device_class == expected_sensor["class"]
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == expected_sensor["result"]
|
||||
for attr in (ATTR_DEVICE_CLASS, ATTR_STATE_CLASS, ATTR_UNIT_OF_MEASUREMENT):
|
||||
assert state.attributes.get(attr) == expected_sensor[attr]
|
||||
|
@ -39,7 +39,7 @@ async def test_owserver_switch(owproxy, hass, device_id):
|
||||
# Force enable switches
|
||||
patch_device_switches = copy.deepcopy(DEVICE_SWITCHES)
|
||||
for item in patch_device_switches[device_id[0:2]]:
|
||||
item["default_disabled"] = False
|
||||
item.entity_registry_enabled_default = True
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.onewire.PLATFORMS", [SWITCH_DOMAIN]
|
||||
|
Loading…
x
Reference in New Issue
Block a user