Skip to content

Commit

Permalink
Drop OWFS support in onewire (#50121)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet committed May 5, 2021
1 parent 4136f9f commit 5dd5941
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 88 deletions.
15 changes: 0 additions & 15 deletions homeassistant/components/onewire/config_flow.py
Expand Up @@ -7,7 +7,6 @@

from .const import (
CONF_MOUNT_DIR,
CONF_TYPE_OWFS,
CONF_TYPE_OWSERVER,
CONF_TYPE_SYSBUS,
DEFAULT_OWSERVER_HOST,
Expand Down Expand Up @@ -166,20 +165,6 @@ async def async_step_import(self, platform_config):
platform_config[CONF_PORT] = DEFAULT_OWSERVER_PORT
return await self.async_step_owserver(platform_config)

# OWFS
if platform_config[CONF_TYPE] == CONF_TYPE_OWFS: # pragma: no cover
# 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
await self.async_set_unique_id(
f"{CONF_TYPE_OWFS}:{platform_config[CONF_MOUNT_DIR]}"
)
self._abort_if_unique_id_configured(
updates=platform_config, reload_on_update=True
)
return self.async_create_entry(
title=platform_config[CONF_MOUNT_DIR], data=platform_config
)

# SysBus
if CONF_MOUNT_DIR not in platform_config:
platform_config[CONF_MOUNT_DIR] = DEFAULT_SYSBUS_MOUNT_DIR
Expand Down
1 change: 0 additions & 1 deletion homeassistant/components/onewire/const.py
Expand Up @@ -20,7 +20,6 @@
CONF_MOUNT_DIR = "mount_dir"
CONF_NAMES = "names"

CONF_TYPE_OWFS = "OWFS"
CONF_TYPE_OWSERVER = "OWServer"
CONF_TYPE_SYSBUS = "SysBus"

Expand Down
72 changes: 0 additions & 72 deletions homeassistant/components/onewire/sensor.py
Expand Up @@ -2,7 +2,6 @@
from __future__ import annotations

import asyncio
from glob import glob
import logging
import os

Expand All @@ -18,7 +17,6 @@
from .const import (
CONF_MOUNT_DIR,
CONF_NAMES,
CONF_TYPE_OWFS,
CONF_TYPE_OWSERVER,
CONF_TYPE_SYSBUS,
DEFAULT_OWSERVER_PORT,
Expand Down Expand Up @@ -242,10 +240,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
config[CONF_TYPE] = CONF_TYPE_OWSERVER
elif config[CONF_MOUNT_DIR] == DEFAULT_SYSBUS_MOUNT_DIR:
config[CONF_TYPE] = CONF_TYPE_SYSBUS
else: # pragma: no cover
# 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
config[CONF_TYPE] = CONF_TYPE_OWFS

hass.async_create_task(
hass.config_entries.flow.async_init(
Expand Down Expand Up @@ -361,38 +355,6 @@ def get_entities(onewirehub: OneWireHub, config):
"Check the mount_dir parameter if it's defined"
)

# We have an owfs mounted
else: # pragma: no cover
# 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
base_dir = config[CONF_MOUNT_DIR]
_LOGGER.debug("Initializing using OWFS %s", base_dir)
_LOGGER.warning(
"The OWFS implementation of 1-Wire sensors is deprecated, "
"and should be migrated to OWServer (on localhost:4304). "
"If migration to OWServer is not feasible on your installation, "
"please raise an issue at https://github.com/home-assistant/core/issues/new"
"?title=Unable%20to%20migrate%20onewire%20from%20OWFS%20to%20OWServer",
)
for family_file_path in glob(os.path.join(base_dir, "*", "family")):
with open(family_file_path) as family_file:
family = family_file.read()
if "EF" in family:
continue
if family in DEVICE_SENSORS:
for sensor_key, sensor_value in DEVICE_SENSORS[family].items():
sensor_id = os.path.split(os.path.split(family_file_path)[0])[1]
device_file = os.path.join(
os.path.split(family_file_path)[0], sensor_value
)
entities.append(
OneWireOWFSSensor(
device_names.get(sensor_id, sensor_id),
device_file,
sensor_key,
)
)

return entities


Expand Down Expand Up @@ -460,37 +422,3 @@ async def async_update(self):
) as ex:
_LOGGER.warning("Cannot read from sensor %s: %s", self._device_file, ex)
self._state = value


class OneWireOWFSSensor(OneWireSensor): # 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:
lines = ds_device_file.readlines()
return lines

def update(self):
"""Get the latest data from the device."""
value = None
try:
value_read = self._read_value_raw()
if len(value_read) == 1:
value = round(float(value_read[0]), 1)
self._value_raw = float(value_read[0])
except ValueError:
_LOGGER.warning("Invalid value read from %s", self._device_file)
except FileNotFoundError:
_LOGGER.warning("Cannot read from sensor: %s", self._device_file)

self._state = value

0 comments on commit 5dd5941

Please sign in to comment.