Update inheritance for onewire entities (#43019)
This commit is contained in:
parent
6f4219d709
commit
7716740c18
4 changed files with 50 additions and 36 deletions
|
@ -10,6 +10,7 @@ from homeassistant.components.sensor import PLATFORM_SCHEMA
|
|||
from homeassistant.config_entries import SOURCE_IMPORT
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_TYPE
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from .const import (
|
||||
CONF_MOUNT_DIR,
|
||||
|
@ -30,7 +31,7 @@ from .const import (
|
|||
SENSOR_TYPE_VOLTAGE,
|
||||
SENSOR_TYPE_WETNESS,
|
||||
)
|
||||
from .onewire_entities import OneWire, OneWireProxy
|
||||
from .onewire_entities import OneWireBaseEntity, OneWireProxyEntity
|
||||
from .onewirehub import OneWireHub
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -277,7 +278,7 @@ def get_entities(onewirehub: OneWireHub, config):
|
|||
os.path.split(device["path"])[0], device_sensor["path"]
|
||||
)
|
||||
entities.append(
|
||||
OneWireProxy(
|
||||
OneWireProxySensor(
|
||||
device_names.get(sensor_id, sensor_id),
|
||||
device_file,
|
||||
device_sensor["type"],
|
||||
|
@ -311,7 +312,7 @@ def get_entities(onewirehub: OneWireHub, config):
|
|||
}
|
||||
device_file = f"/sys/bus/w1/devices/{sensor_id}/w1_slave"
|
||||
entities.append(
|
||||
OneWireDirect(
|
||||
OneWireDirectSensor(
|
||||
device_names.get(sensor_id, sensor_id),
|
||||
device_file,
|
||||
device_info,
|
||||
|
@ -350,7 +351,7 @@ def get_entities(onewirehub: OneWireHub, config):
|
|||
os.path.split(family_file_path)[0], sensor_value
|
||||
)
|
||||
entities.append(
|
||||
OneWireOWFS(
|
||||
OneWireOWFSSensor(
|
||||
device_names.get(sensor_id, sensor_id),
|
||||
device_file,
|
||||
sensor_key,
|
||||
|
@ -360,7 +361,16 @@ def get_entities(onewirehub: OneWireHub, config):
|
|||
return entities
|
||||
|
||||
|
||||
class OneWireDirect(OneWire):
|
||||
class OneWireProxySensor(OneWireProxyEntity):
|
||||
"""Implementation of a 1-Wire sensor connected through owserver."""
|
||||
|
||||
@property
|
||||
def state(self) -> StateType:
|
||||
"""Return the state of the entity."""
|
||||
return self._state
|
||||
|
||||
|
||||
class OneWireDirectSensor(OneWireBaseEntity):
|
||||
"""Implementation of a 1-Wire sensor directly connected to RPI GPIO."""
|
||||
|
||||
def __init__(self, name, device_file, device_info, owsensor):
|
||||
|
@ -368,6 +378,11 @@ class OneWireDirect(OneWire):
|
|||
super().__init__(name, device_file, "temperature", "Temperature", device_info)
|
||||
self._owsensor = owsensor
|
||||
|
||||
@property
|
||||
def state(self) -> StateType:
|
||||
"""Return the state of the entity."""
|
||||
return self._state
|
||||
|
||||
def update(self):
|
||||
"""Get the latest data from the device."""
|
||||
value = None
|
||||
|
@ -383,13 +398,18 @@ class OneWireDirect(OneWire):
|
|||
self._state = value
|
||||
|
||||
|
||||
class OneWireOWFS(OneWire): # pragma: no cover
|
||||
class OneWireOWFSSensor(OneWireBaseEntity): # pragma: no cover
|
||||
"""Implementation of a 1-Wire sensor through owfs.
|
||||
|
||||
This part of the implementation does not conform to policy regarding 3rd-party libraries, and will not longer be updated.
|
||||
https://developers.home-assistant.io/docs/creating_platform_code_review/#5-communication-with-devicesservices
|
||||
"""
|
||||
|
||||
@property
|
||||
def state(self) -> StateType:
|
||||
"""Return the state of the entity."""
|
||||
return self._state
|
||||
|
||||
def _read_value_raw(self):
|
||||
"""Read the value as it is returned by the sensor."""
|
||||
with open(self._device_file) as ds_device_file:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue