From 0b20b107e198de87026fe973847f06c15847491a Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 26 Feb 2022 22:33:12 +0100 Subject: [PATCH] Remove deprecated Sense HAT integration (#67272) --- .coveragerc | 2 - homeassistant/components/sensehat/__init__.py | 1 - homeassistant/components/sensehat/light.py | 125 -------------- .../components/sensehat/manifest.json | 9 - homeassistant/components/sensehat/sensor.py | 163 ------------------ requirements_all.txt | 3 - 6 files changed, 303 deletions(-) delete mode 100644 homeassistant/components/sensehat/__init__.py delete mode 100644 homeassistant/components/sensehat/light.py delete mode 100644 homeassistant/components/sensehat/manifest.json delete mode 100644 homeassistant/components/sensehat/sensor.py diff --git a/.coveragerc b/.coveragerc index 47f8b12287c..24bddce6859 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1012,8 +1012,6 @@ omit = homeassistant/components/sense/__init__.py homeassistant/components/sense/binary_sensor.py homeassistant/components/sense/sensor.py - homeassistant/components/sensehat/light.py - homeassistant/components/sensehat/sensor.py homeassistant/components/senseme/__init__.py homeassistant/components/senseme/binary_sensor.py homeassistant/components/senseme/discovery.py diff --git a/homeassistant/components/sensehat/__init__.py b/homeassistant/components/sensehat/__init__.py deleted file mode 100644 index baef85d7f53..00000000000 --- a/homeassistant/components/sensehat/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""The sensehat component.""" diff --git a/homeassistant/components/sensehat/light.py b/homeassistant/components/sensehat/light.py deleted file mode 100644 index c1184576362..00000000000 --- a/homeassistant/components/sensehat/light.py +++ /dev/null @@ -1,125 +0,0 @@ -"""Support for Sense Hat LEDs.""" -from __future__ import annotations - -import logging - -from sense_hat import SenseHat -import voluptuous as vol - -from homeassistant.components.light import ( - ATTR_BRIGHTNESS, - ATTR_HS_COLOR, - PLATFORM_SCHEMA, - SUPPORT_BRIGHTNESS, - SUPPORT_COLOR, - LightEntity, -) -from homeassistant.const import CONF_NAME -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 -import homeassistant.util.color as color_util - -SUPPORT_SENSEHAT = SUPPORT_BRIGHTNESS | SUPPORT_COLOR - -DEFAULT_NAME = "sensehat" - -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - {vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string} -) - -_LOGGER = logging.getLogger(__name__) - - -def setup_platform( - hass: HomeAssistant, - config: ConfigType, - add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up the Sense Hat Light platform.""" - _LOGGER.warning( - "The Sense HAT 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" - ) - - sensehat = SenseHat() - - name = config.get(CONF_NAME) - - add_entities([SenseHatLight(sensehat, name)]) - - -class SenseHatLight(LightEntity): - """Representation of an Sense Hat Light.""" - - def __init__(self, sensehat, name): - """Initialize an Sense Hat Light. - - Full brightness and white color. - """ - self._sensehat = sensehat - self._name = name - self._is_on = False - self._brightness = 255 - self._hs_color = [0, 0] - - @property - def name(self): - """Return the display name of this light.""" - return self._name - - @property - def brightness(self): - """Read back the brightness of the light.""" - return self._brightness - - @property - def hs_color(self): - """Read back the color of the light.""" - return self._hs_color - - @property - def supported_features(self): - """Flag supported features.""" - return SUPPORT_SENSEHAT - - @property - def is_on(self): - """Return true if light is on.""" - return self._is_on - - @property - def should_poll(self): - """Return if we should poll this device.""" - return False - - @property - def assumed_state(self) -> bool: - """Return True if unable to access real state of the entity.""" - return True - - def turn_on(self, **kwargs): - """Instruct the light to turn on and set correct brightness & color.""" - if ATTR_BRIGHTNESS in kwargs: - self._brightness = kwargs[ATTR_BRIGHTNESS] - - if ATTR_HS_COLOR in kwargs: - self._hs_color = kwargs[ATTR_HS_COLOR] - - rgb = color_util.color_hsv_to_RGB( - self._hs_color[0], self._hs_color[1], self._brightness / 255 * 100 - ) - self._sensehat.clear(*rgb) - - self._is_on = True - self.schedule_update_ha_state() - - def turn_off(self, **kwargs): - """Instruct the light to turn off.""" - self._sensehat.clear() - self._is_on = False - self.schedule_update_ha_state() diff --git a/homeassistant/components/sensehat/manifest.json b/homeassistant/components/sensehat/manifest.json deleted file mode 100644 index 78f6e0609bc..00000000000 --- a/homeassistant/components/sensehat/manifest.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "domain": "sensehat", - "name": "Sense HAT", - "documentation": "https://www.home-assistant.io/integrations/sensehat", - "requirements": ["sense-hat==2.2.0"], - "codeowners": [], - "iot_class": "assumed_state", - "loggers": ["sense_hat"] -} diff --git a/homeassistant/components/sensehat/sensor.py b/homeassistant/components/sensehat/sensor.py deleted file mode 100644 index bf9d77104da..00000000000 --- a/homeassistant/components/sensehat/sensor.py +++ /dev/null @@ -1,163 +0,0 @@ -"""Support for Sense HAT sensors.""" -from __future__ import annotations - -from datetime import timedelta -import logging -from pathlib import Path - -from sense_hat import SenseHat -import voluptuous as vol - -from homeassistant.components.sensor import ( - PLATFORM_SCHEMA, - SensorDeviceClass, - SensorEntity, - SensorEntityDescription, -) -from homeassistant.const import ( - CONF_DISPLAY_OPTIONS, - CONF_NAME, - PERCENTAGE, - TEMP_CELSIUS, -) -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 -from homeassistant.util import Throttle - -_LOGGER = logging.getLogger(__name__) - -DEFAULT_NAME = "sensehat" -CONF_IS_HAT_ATTACHED = "is_hat_attached" - -MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60) - -SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( - SensorEntityDescription( - key="temperature", - name="temperature", - native_unit_of_measurement=TEMP_CELSIUS, - device_class=SensorDeviceClass.TEMPERATURE, - ), - SensorEntityDescription( - key="humidity", - name="humidity", - native_unit_of_measurement=PERCENTAGE, - ), - SensorEntityDescription( - key="pressure", - name="pressure", - native_unit_of_measurement="mb", - ), -) - -SENSOR_KEYS: list[str] = [desc.key for desc in SENSOR_TYPES] - -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - { - vol.Required(CONF_DISPLAY_OPTIONS, default=SENSOR_KEYS): [vol.In(SENSOR_KEYS)], - vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, - vol.Optional(CONF_IS_HAT_ATTACHED, default=True): cv.boolean, - } -) - - -def get_cpu_temp(): - """Get CPU temperature.""" - t_cpu = ( - Path("/sys/class/thermal/thermal_zone0/temp") - .read_text(encoding="utf-8") - .strip() - ) - return float(t_cpu) * 0.001 - - -def get_average(temp_base): - """Use moving average to get better readings.""" - if not hasattr(get_average, "temp"): - get_average.temp = [temp_base, temp_base, temp_base] - get_average.temp[2] = get_average.temp[1] - get_average.temp[1] = get_average.temp[0] - get_average.temp[0] = temp_base - temp_avg = (get_average.temp[0] + get_average.temp[1] + get_average.temp[2]) / 3 - return temp_avg - - -def setup_platform( - hass: HomeAssistant, - config: ConfigType, - add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up the Sense HAT sensor platform.""" - _LOGGER.warning( - "The Sense HAT 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" - ) - data = SenseHatData(config.get(CONF_IS_HAT_ATTACHED)) - display_options = config[CONF_DISPLAY_OPTIONS] - entities = [ - SenseHatSensor(data, description) - for description in SENSOR_TYPES - if description.key in display_options - ] - - add_entities(entities, True) - - -class SenseHatSensor(SensorEntity): - """Representation of a Sense HAT sensor.""" - - def __init__(self, data, description: SensorEntityDescription): - """Initialize the sensor.""" - self.entity_description = description - self.data = data - - def update(self): - """Get the latest data and updates the states.""" - self.data.update() - if not self.data.humidity: - _LOGGER.error("Don't receive data") - return - - sensor_type = self.entity_description.key - if sensor_type == "temperature": - self._attr_native_value = self.data.temperature - elif sensor_type == "humidity": - self._attr_native_value = self.data.humidity - elif sensor_type == "pressure": - self._attr_native_value = self.data.pressure - - -class SenseHatData: - """Get the latest data and update.""" - - def __init__(self, is_hat_attached): - """Initialize the data object.""" - self.temperature = None - self.humidity = None - self.pressure = None - self.is_hat_attached = is_hat_attached - - @Throttle(MIN_TIME_BETWEEN_UPDATES) - def update(self): - """Get the latest data from Sense HAT.""" - - sense = SenseHat() - temp_from_h = sense.get_temperature_from_humidity() - temp_from_p = sense.get_temperature_from_pressure() - t_total = (temp_from_h + temp_from_p) / 2 - - if self.is_hat_attached: - t_cpu = get_cpu_temp() - t_correct = t_total - ((t_cpu - t_total) / 1.5) - t_correct = get_average(t_correct) - else: - t_correct = get_average(t_total) - - self.temperature = t_correct - self.humidity = sense.get_humidity() - self.pressure = sense.get_pressure() diff --git a/requirements_all.txt b/requirements_all.txt index 3cfbc63a9fc..a233cd2652d 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2137,9 +2137,6 @@ scsgate==0.1.0 # homeassistant.components.sendgrid sendgrid==6.8.2 -# homeassistant.components.sensehat -sense-hat==2.2.0 - # homeassistant.components.emulated_kasa # homeassistant.components.sense sense_energy==0.10.2