From d495bded5c0ae447bfeb1824269b547aa306949e Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Thu, 24 Feb 2022 18:23:32 +0100 Subject: [PATCH] Remove deprecated BH1750 integration (#67161) --- .coveragerc | 1 - homeassistant/components/bh1750/__init__.py | 1 - homeassistant/components/bh1750/manifest.json | 9 -- homeassistant/components/bh1750/sensor.py | 138 ------------------ requirements_all.txt | 2 - 5 files changed, 151 deletions(-) delete mode 100644 homeassistant/components/bh1750/__init__.py delete mode 100644 homeassistant/components/bh1750/manifest.json delete mode 100644 homeassistant/components/bh1750/sensor.py diff --git a/.coveragerc b/.coveragerc index 3262c2703eb..78a07b8d916 100644 --- a/.coveragerc +++ b/.coveragerc @@ -103,7 +103,6 @@ omit = homeassistant/components/beewi_smartclim/sensor.py homeassistant/components/bbox/device_tracker.py homeassistant/components/bbox/sensor.py - homeassistant/components/bh1750/sensor.py homeassistant/components/bitcoin/sensor.py homeassistant/components/bizkaibus/sensor.py homeassistant/components/blink/__init__.py diff --git a/homeassistant/components/bh1750/__init__.py b/homeassistant/components/bh1750/__init__.py deleted file mode 100644 index ce7ecc65366..00000000000 --- a/homeassistant/components/bh1750/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""The bh1750 component.""" diff --git a/homeassistant/components/bh1750/manifest.json b/homeassistant/components/bh1750/manifest.json deleted file mode 100644 index 807f7a9e05f..00000000000 --- a/homeassistant/components/bh1750/manifest.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "domain": "bh1750", - "name": "BH1750", - "documentation": "https://www.home-assistant.io/integrations/bh1750", - "requirements": ["i2csense==0.0.4", "smbus-cffi==0.5.1"], - "codeowners": [], - "iot_class": "local_push", - "loggers": ["i2csense", "smbus"] -} diff --git a/homeassistant/components/bh1750/sensor.py b/homeassistant/components/bh1750/sensor.py deleted file mode 100644 index d6239f90d43..00000000000 --- a/homeassistant/components/bh1750/sensor.py +++ /dev/null @@ -1,138 +0,0 @@ -"""Support for BH1750 light sensor.""" -from __future__ import annotations - -from functools import partial -import logging - -from i2csense.bh1750 import BH1750 # pylint: disable=import-error -import smbus -import voluptuous as vol - -from homeassistant.components.sensor import ( - PLATFORM_SCHEMA, - SensorDeviceClass, - SensorEntity, -) -from homeassistant.const import CONF_NAME, LIGHT_LUX -from homeassistant.core import HomeAssistant -import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType - -_LOGGER = logging.getLogger(__name__) - -CONF_I2C_ADDRESS = "i2c_address" -CONF_I2C_BUS = "i2c_bus" -CONF_OPERATION_MODE = "operation_mode" -CONF_SENSITIVITY = "sensitivity" -CONF_DELAY = "measurement_delay_ms" -CONF_MULTIPLIER = "multiplier" - -# Operation modes for BH1750 sensor (from the datasheet). Time typically 120ms -# In one time measurements, device is set to Power Down after each sample. -CONTINUOUS_LOW_RES_MODE = "continuous_low_res_mode" -CONTINUOUS_HIGH_RES_MODE_1 = "continuous_high_res_mode_1" -CONTINUOUS_HIGH_RES_MODE_2 = "continuous_high_res_mode_2" -ONE_TIME_LOW_RES_MODE = "one_time_low_res_mode" -ONE_TIME_HIGH_RES_MODE_1 = "one_time_high_res_mode_1" -ONE_TIME_HIGH_RES_MODE_2 = "one_time_high_res_mode_2" -OPERATION_MODES = { - CONTINUOUS_LOW_RES_MODE: (0x13, True), # 4lx resolution - CONTINUOUS_HIGH_RES_MODE_1: (0x10, True), # 1lx resolution. - CONTINUOUS_HIGH_RES_MODE_2: (0x11, True), # 0.5lx resolution. - ONE_TIME_LOW_RES_MODE: (0x23, False), # 4lx resolution. - ONE_TIME_HIGH_RES_MODE_1: (0x20, False), # 1lx resolution. - ONE_TIME_HIGH_RES_MODE_2: (0x21, False), # 0.5lx resolution. -} - -DEFAULT_NAME = "BH1750 Light Sensor" -DEFAULT_I2C_ADDRESS = "0x23" -DEFAULT_I2C_BUS = 1 -DEFAULT_MODE = CONTINUOUS_HIGH_RES_MODE_1 -DEFAULT_DELAY_MS = 120 -DEFAULT_SENSITIVITY = 69 # from 31 to 254 - -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - { - vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, - vol.Optional(CONF_I2C_ADDRESS, default=DEFAULT_I2C_ADDRESS): cv.string, - vol.Optional(CONF_I2C_BUS, default=DEFAULT_I2C_BUS): vol.Coerce(int), - vol.Optional(CONF_OPERATION_MODE, default=DEFAULT_MODE): vol.In( - OPERATION_MODES - ), - vol.Optional(CONF_SENSITIVITY, default=DEFAULT_SENSITIVITY): cv.positive_int, - vol.Optional(CONF_DELAY, default=DEFAULT_DELAY_MS): cv.positive_int, - vol.Optional(CONF_MULTIPLIER, default=1.0): vol.Range(min=0.1, max=10), - } -) - - -async def async_setup_platform( - hass: HomeAssistant, - config: ConfigType, - async_add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up the BH1750 sensor.""" - _LOGGER.warning( - "The BH1750 integration is deprecated and will be removed " - "in Home Assistant Core 2022.4; this integration is removed under " - "Architectural Decision Record 0019, more information can be found here: " - "https://github.com/home-assistant/architecture/blob/master/adr/0019-GPIO.md" - ) - - name = config[CONF_NAME] - bus_number = config[CONF_I2C_BUS] - i2c_address = config[CONF_I2C_ADDRESS] - operation_mode = config[CONF_OPERATION_MODE] - - bus = smbus.SMBus(bus_number) - - sensor = await hass.async_add_executor_job( - partial( - BH1750, - bus, - i2c_address, - operation_mode=operation_mode, - measurement_delay=config[CONF_DELAY], - sensitivity=config[CONF_SENSITIVITY], - logger=_LOGGER, - ) - ) - if not sensor.sample_ok: - _LOGGER.error("BH1750 sensor not detected at %s", i2c_address) - return - - dev = [BH1750Sensor(sensor, name, LIGHT_LUX, config[CONF_MULTIPLIER])] - _LOGGER.info( - "Setup of BH1750 light sensor at %s in mode %s is complete", - i2c_address, - operation_mode, - ) - - async_add_entities(dev, True) - - -class BH1750Sensor(SensorEntity): - """Implementation of the BH1750 sensor.""" - - _attr_device_class = SensorDeviceClass.ILLUMINANCE - - def __init__(self, bh1750_sensor, name, unit, multiplier=1.0): - """Initialize the sensor.""" - self._attr_name = name - self._attr_native_unit_of_measurement = unit - self._multiplier = multiplier - self.bh1750_sensor = bh1750_sensor - - async def async_update(self): - """Get the latest data from the BH1750 and update the states.""" - await self.hass.async_add_executor_job(self.bh1750_sensor.update) - if self.bh1750_sensor.sample_ok and self.bh1750_sensor.light_level >= 0: - self._attr_native_value = int( - round(self.bh1750_sensor.light_level * self._multiplier) - ) - else: - _LOGGER.warning( - "Bad Update of sensor.%s: %s", self.name, self.bh1750_sensor.light_level - ) diff --git a/requirements_all.txt b/requirements_all.txt index f5def50096e..966866f3403 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -867,7 +867,6 @@ hydrawiser==0.2 # homeassistant.components.hyperion hyperion-py==0.7.4 -# homeassistant.components.bh1750 # homeassistant.components.bme280 # homeassistant.components.htu21d # i2csense==0.0.4 @@ -2214,7 +2213,6 @@ smart-meter-texas==0.4.7 # homeassistant.components.smarthab smarthab==0.21 -# homeassistant.components.bh1750 # homeassistant.components.bme280 # homeassistant.components.bme680 # homeassistant.components.envirophat