From a5493f79477761a4f446e5ac83b917ed95836844 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 24 Oct 2024 11:52:00 +0200 Subject: [PATCH] Remove bloomsky integration (#129073) * Small refactor to bloomsky * Remove bloomsky integration * Update integrations.json --- homeassistant/components/bloomsky/__init__.py | 83 ------------- .../components/bloomsky/binary_sensor.py | 68 ----------- homeassistant/components/bloomsky/camera.py | 67 ---------- .../components/bloomsky/manifest.json | 7 -- homeassistant/components/bloomsky/sensor.py | 115 ------------------ homeassistant/generated/integrations.json | 6 - 6 files changed, 346 deletions(-) delete mode 100644 homeassistant/components/bloomsky/__init__.py delete mode 100644 homeassistant/components/bloomsky/binary_sensor.py delete mode 100644 homeassistant/components/bloomsky/camera.py delete mode 100644 homeassistant/components/bloomsky/manifest.json delete mode 100644 homeassistant/components/bloomsky/sensor.py diff --git a/homeassistant/components/bloomsky/__init__.py b/homeassistant/components/bloomsky/__init__.py deleted file mode 100644 index c2a46baaeb3..00000000000 --- a/homeassistant/components/bloomsky/__init__.py +++ /dev/null @@ -1,83 +0,0 @@ -"""Support for BloomSky weather station.""" - -from datetime import timedelta -from http import HTTPStatus -import logging - -import requests -import voluptuous as vol - -from homeassistant.const import CONF_API_KEY, Platform -from homeassistant.core import HomeAssistant -from homeassistant.helpers import discovery -import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.typing import ConfigType -from homeassistant.util import Throttle -from homeassistant.util.unit_system import METRIC_SYSTEM - -_LOGGER = logging.getLogger(__name__) - -PLATFORMS = [Platform.BINARY_SENSOR, Platform.CAMERA, Platform.SENSOR] - -DOMAIN = "bloomsky" - -# The BloomSky only updates every 5-8 minutes as per the API spec so there's -# no point in polling the API more frequently -MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=300) - -CONFIG_SCHEMA = vol.Schema( - {DOMAIN: vol.Schema({vol.Required(CONF_API_KEY): cv.string})}, extra=vol.ALLOW_EXTRA -) - - -def setup(hass: HomeAssistant, config: ConfigType) -> bool: - """Set up the BloomSky integration.""" - api_key = config[DOMAIN][CONF_API_KEY] - - try: - bloomsky = BloomSky(api_key, hass.config.units is METRIC_SYSTEM) - except RuntimeError: - return False - - hass.data[DOMAIN] = bloomsky - - for platform in PLATFORMS: - discovery.load_platform(hass, platform, DOMAIN, {}, config) - - return True - - -class BloomSky: - """Handle all communication with the BloomSky API.""" - - # API documentation at http://weatherlution.com/bloomsky-api/ - API_URL = "http://api.bloomsky.com/api/skydata" - - def __init__(self, api_key, is_metric): - """Initialize the BookSky.""" - self._api_key = api_key - self._endpoint_argument = "unit=intl" if is_metric else "" - self.devices = {} - self.is_metric = is_metric - _LOGGER.debug("Initial BloomSky device load") - self.refresh_devices() - - @Throttle(MIN_TIME_BETWEEN_UPDATES) - def refresh_devices(self): - """Use the API to retrieve a list of devices.""" - _LOGGER.debug("Fetching BloomSky update") - response = requests.get( - f"{self.API_URL}?{self._endpoint_argument}", - headers={"Authorization": self._api_key}, - timeout=10, - ) - if response.status_code == HTTPStatus.UNAUTHORIZED: - raise RuntimeError("Invalid API_KEY") - if response.status_code == HTTPStatus.METHOD_NOT_ALLOWED: - _LOGGER.error("You have no bloomsky devices configured") - return - if response.status_code != HTTPStatus.OK: - _LOGGER.error("Invalid HTTP response: %s", response.status_code) - return - # Create dictionary keyed off of the device unique id - self.devices.update({device["DeviceID"]: device for device in response.json()}) diff --git a/homeassistant/components/bloomsky/binary_sensor.py b/homeassistant/components/bloomsky/binary_sensor.py deleted file mode 100644 index 12d55f971e1..00000000000 --- a/homeassistant/components/bloomsky/binary_sensor.py +++ /dev/null @@ -1,68 +0,0 @@ -"""Support the binary sensors of a BloomSky weather station.""" - -from __future__ import annotations - -import voluptuous as vol - -from homeassistant.components.binary_sensor import ( - PLATFORM_SCHEMA as BINARY_SENSOR_PLATFORM_SCHEMA, - BinarySensorDeviceClass, - BinarySensorEntity, -) -from homeassistant.const import CONF_MONITORED_CONDITIONS -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 . import DOMAIN - -SENSOR_TYPES = {"Rain": BinarySensorDeviceClass.MOISTURE, "Night": None} - -PLATFORM_SCHEMA = BINARY_SENSOR_PLATFORM_SCHEMA.extend( - { - vol.Optional(CONF_MONITORED_CONDITIONS, default=list(SENSOR_TYPES)): vol.All( - cv.ensure_list, [vol.In(SENSOR_TYPES)] - ) - } -) - - -def setup_platform( - hass: HomeAssistant, - config: ConfigType, - add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up the available BloomSky weather binary sensors.""" - # Default needed in case of discovery - if discovery_info is not None: - return - - sensors = config[CONF_MONITORED_CONDITIONS] - bloomsky = hass.data[DOMAIN] - - for device in bloomsky.devices.values(): - for variable in sensors: - add_entities([BloomSkySensor(bloomsky, device, variable)], True) - - -class BloomSkySensor(BinarySensorEntity): - """Representation of a single binary sensor in a BloomSky device.""" - - def __init__(self, bs, device, sensor_name): - """Initialize a BloomSky binary sensor.""" - self._bloomsky = bs - self._device_id = device["DeviceID"] - self._sensor_name = sensor_name - self._attr_name = f"{device['DeviceName']} {sensor_name}" - self._attr_unique_id = f"{self._device_id}-{sensor_name}" - self._attr_device_class = SENSOR_TYPES.get(sensor_name) - - def update(self) -> None: - """Request an update from the BloomSky API.""" - self._bloomsky.refresh_devices() - - self._attr_is_on = self._bloomsky.devices[self._device_id]["Data"][ - self._sensor_name - ] diff --git a/homeassistant/components/bloomsky/camera.py b/homeassistant/components/bloomsky/camera.py deleted file mode 100644 index f07dd1e9d14..00000000000 --- a/homeassistant/components/bloomsky/camera.py +++ /dev/null @@ -1,67 +0,0 @@ -"""Support for a camera of a BloomSky weather station.""" - -from __future__ import annotations - -import logging - -import requests - -from homeassistant.components.camera import Camera -from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType - -from . import DOMAIN - - -def setup_platform( - hass: HomeAssistant, - config: ConfigType, - add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up access to BloomSky cameras.""" - if discovery_info is not None: - return - - bloomsky = hass.data[DOMAIN] - - for device in bloomsky.devices.values(): - add_entities([BloomSkyCamera(bloomsky, device)]) - - -class BloomSkyCamera(Camera): - """Representation of the images published from the BloomSky's camera.""" - - def __init__(self, bs, device): - """Initialize access to the BloomSky camera images.""" - super().__init__() - self._attr_name = device["DeviceName"] - self._id = device["DeviceID"] - self._bloomsky = bs - self._url = "" - self._last_url = "" - # last_image will store images as they are downloaded so that the - # frequent updates in home-assistant don't keep poking the server - # to download the same image over and over. - self._last_image = "" - self._logger = logging.getLogger(__name__) - self._attr_unique_id = self._id - - def camera_image( - self, width: int | None = None, height: int | None = None - ) -> bytes | None: - """Update the camera's image if it has changed.""" - try: - self._url = self._bloomsky.devices[self._id]["Data"]["ImageURL"] - self._bloomsky.refresh_devices() - # If the URL hasn't changed then the image hasn't changed. - if self._url != self._last_url: - response = requests.get(self._url, timeout=10) - self._last_url = self._url - self._last_image = response.content - except requests.exceptions.RequestException as error: - self._logger.error("Error getting bloomsky image: %s", error) - return None - - return self._last_image diff --git a/homeassistant/components/bloomsky/manifest.json b/homeassistant/components/bloomsky/manifest.json deleted file mode 100644 index 65d302df239..00000000000 --- a/homeassistant/components/bloomsky/manifest.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "domain": "bloomsky", - "name": "BloomSky", - "codeowners": [], - "documentation": "https://www.home-assistant.io/integrations/bloomsky", - "iot_class": "cloud_polling" -} diff --git a/homeassistant/components/bloomsky/sensor.py b/homeassistant/components/bloomsky/sensor.py deleted file mode 100644 index 6d99506bd44..00000000000 --- a/homeassistant/components/bloomsky/sensor.py +++ /dev/null @@ -1,115 +0,0 @@ -"""Support the sensor of a BloomSky weather station.""" - -from __future__ import annotations - -import voluptuous as vol - -from homeassistant.components.sensor import ( - PLATFORM_SCHEMA as SENSOR_PLATFORM_SCHEMA, - SensorDeviceClass, - SensorEntity, -) -from homeassistant.const import ( - AREA_SQUARE_METERS, - CONF_MONITORED_CONDITIONS, - PERCENTAGE, - UnitOfElectricPotential, - UnitOfPressure, - UnitOfTemperature, -) -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 . import DOMAIN - -# These are the available sensors -SENSOR_TYPES = [ - "Temperature", - "Humidity", - "Pressure", - "Luminance", - "UVIndex", - "Voltage", -] - -# Sensor units - these do not currently align with the API documentation -SENSOR_UNITS_IMPERIAL = { - "Temperature": UnitOfTemperature.FAHRENHEIT, - "Humidity": PERCENTAGE, - "Pressure": UnitOfPressure.INHG, - "Luminance": f"cd/{AREA_SQUARE_METERS}", - "Voltage": UnitOfElectricPotential.MILLIVOLT, -} - -# Metric units -SENSOR_UNITS_METRIC = { - "Temperature": UnitOfTemperature.CELSIUS, - "Humidity": PERCENTAGE, - "Pressure": UnitOfPressure.MBAR, - "Luminance": f"cd/{AREA_SQUARE_METERS}", - "Voltage": UnitOfElectricPotential.MILLIVOLT, -} - -# Device class -SENSOR_DEVICE_CLASS = { - "Temperature": SensorDeviceClass.TEMPERATURE, - "Humidity": SensorDeviceClass.HUMIDITY, - "Pressure": SensorDeviceClass.PRESSURE, - "Voltage": SensorDeviceClass.VOLTAGE, -} - -# Which sensors to format numerically -FORMAT_NUMBERS = ["Temperature", "Pressure", "Voltage"] - -PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend( - { - vol.Optional(CONF_MONITORED_CONDITIONS, default=SENSOR_TYPES): vol.All( - cv.ensure_list, [vol.In(SENSOR_TYPES)] - ) - } -) - - -def setup_platform( - hass: HomeAssistant, - config: ConfigType, - add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up the available BloomSky weather sensors.""" - # Default needed in case of discovery - if discovery_info is not None: - return - - sensors = config[CONF_MONITORED_CONDITIONS] - bloomsky = hass.data[DOMAIN] - - for device in bloomsky.devices.values(): - for variable in sensors: - add_entities([BloomSkySensor(bloomsky, device, variable)], True) - - -class BloomSkySensor(SensorEntity): - """Representation of a single sensor in a BloomSky device.""" - - def __init__(self, bs, device, sensor_name): - """Initialize a BloomSky sensor.""" - self._bloomsky = bs - self._device_id = device["DeviceID"] - self._sensor_name = sensor_name - self._attr_name = f"{device['DeviceName']} {sensor_name}" - self._attr_unique_id = f"{self._device_id}-{sensor_name}" - self._attr_device_class = SENSOR_DEVICE_CLASS.get(sensor_name) - self._attr_native_unit_of_measurement = SENSOR_UNITS_IMPERIAL.get(sensor_name) - if self._bloomsky.is_metric: - self._attr_native_unit_of_measurement = SENSOR_UNITS_METRIC.get(sensor_name) - - def update(self) -> None: - """Request an update from the BloomSky API.""" - self._bloomsky.refresh_devices() - state = self._bloomsky.devices[self._device_id]["Data"][self._sensor_name] - self._attr_native_value = ( - f"{state:.2f}" if self._sensor_name in FORMAT_NUMBERS else state - ) diff --git a/homeassistant/generated/integrations.json b/homeassistant/generated/integrations.json index 404d2da7c9b..701757458ed 100644 --- a/homeassistant/generated/integrations.json +++ b/homeassistant/generated/integrations.json @@ -698,12 +698,6 @@ "config_flow": false, "iot_class": "cloud_polling" }, - "bloomsky": { - "name": "BloomSky", - "integration_type": "hub", - "config_flow": false, - "iot_class": "cloud_polling" - }, "blue_current": { "name": "Blue Current", "integration_type": "hub",