mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Remove deprecated Sense HAT integration (#67272)
This commit is contained in:
parent
3b2b2b9c69
commit
0b20b107e1
@ -1012,8 +1012,6 @@ omit =
|
|||||||
homeassistant/components/sense/__init__.py
|
homeassistant/components/sense/__init__.py
|
||||||
homeassistant/components/sense/binary_sensor.py
|
homeassistant/components/sense/binary_sensor.py
|
||||||
homeassistant/components/sense/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/__init__.py
|
||||||
homeassistant/components/senseme/binary_sensor.py
|
homeassistant/components/senseme/binary_sensor.py
|
||||||
homeassistant/components/senseme/discovery.py
|
homeassistant/components/senseme/discovery.py
|
||||||
|
@ -1 +0,0 @@
|
|||||||
"""The sensehat component."""
|
|
@ -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()
|
|
@ -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"]
|
|
||||||
}
|
|
@ -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()
|
|
@ -2137,9 +2137,6 @@ scsgate==0.1.0
|
|||||||
# homeassistant.components.sendgrid
|
# homeassistant.components.sendgrid
|
||||||
sendgrid==6.8.2
|
sendgrid==6.8.2
|
||||||
|
|
||||||
# homeassistant.components.sensehat
|
|
||||||
sense-hat==2.2.0
|
|
||||||
|
|
||||||
# homeassistant.components.emulated_kasa
|
# homeassistant.components.emulated_kasa
|
||||||
# homeassistant.components.sense
|
# homeassistant.components.sense
|
||||||
sense_energy==0.10.2
|
sense_energy==0.10.2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user