mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Remove gearbest integration (ADR-0004) (#36347)
This commit is contained in:
parent
1c663dc179
commit
e5d81aeb2a
@ -275,7 +275,6 @@ omit =
|
|||||||
homeassistant/components/garmin_connect/sensor.py
|
homeassistant/components/garmin_connect/sensor.py
|
||||||
homeassistant/components/gc100/*
|
homeassistant/components/gc100/*
|
||||||
homeassistant/components/geniushub/*
|
homeassistant/components/geniushub/*
|
||||||
homeassistant/components/gearbest/sensor.py
|
|
||||||
homeassistant/components/geizhals/sensor.py
|
homeassistant/components/geizhals/sensor.py
|
||||||
homeassistant/components/gios/__init__.py
|
homeassistant/components/gios/__init__.py
|
||||||
homeassistant/components/gios/air_quality.py
|
homeassistant/components/gios/air_quality.py
|
||||||
|
@ -141,7 +141,6 @@ homeassistant/components/fronius/* @nielstron
|
|||||||
homeassistant/components/frontend/* @home-assistant/frontend
|
homeassistant/components/frontend/* @home-assistant/frontend
|
||||||
homeassistant/components/garmin_connect/* @cyberjunky
|
homeassistant/components/garmin_connect/* @cyberjunky
|
||||||
homeassistant/components/gdacs/* @exxamalte
|
homeassistant/components/gdacs/* @exxamalte
|
||||||
homeassistant/components/gearbest/* @HerrHofrat
|
|
||||||
homeassistant/components/geniushub/* @zxdavb
|
homeassistant/components/geniushub/* @zxdavb
|
||||||
homeassistant/components/geo_rss_events/* @exxamalte
|
homeassistant/components/geo_rss_events/* @exxamalte
|
||||||
homeassistant/components/geonetnz_quakes/* @exxamalte
|
homeassistant/components/geonetnz_quakes/* @exxamalte
|
||||||
|
@ -1 +0,0 @@
|
|||||||
"""The gearbest component."""
|
|
@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"domain": "gearbest",
|
|
||||||
"name": "Gearbest",
|
|
||||||
"documentation": "https://www.home-assistant.io/integrations/gearbest",
|
|
||||||
"requirements": ["gearbest_parser==1.0.7"],
|
|
||||||
"codeowners": ["@HerrHofrat"]
|
|
||||||
}
|
|
@ -1,123 +0,0 @@
|
|||||||
"""Parse prices of an item from gearbest."""
|
|
||||||
from datetime import timedelta
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from gearbest_parser import CurrencyConverter, GearbestParser
|
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
|
||||||
from homeassistant.const import CONF_CURRENCY, CONF_ID, CONF_NAME, CONF_URL
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
from homeassistant.helpers.entity import Entity
|
|
||||||
from homeassistant.helpers.event import track_time_interval
|
|
||||||
from homeassistant.util import Throttle
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
CONF_ITEMS = "items"
|
|
||||||
|
|
||||||
ICON = "mdi:coin"
|
|
||||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=2 * 60 * 60) # 2h
|
|
||||||
MIN_TIME_BETWEEN_CURRENCY_UPDATES = timedelta(seconds=12 * 60 * 60) # 12h
|
|
||||||
|
|
||||||
|
|
||||||
_ITEM_SCHEMA = vol.All(
|
|
||||||
vol.Schema(
|
|
||||||
{
|
|
||||||
vol.Exclusive(CONF_URL, "XOR"): cv.string,
|
|
||||||
vol.Exclusive(CONF_ID, "XOR"): cv.string,
|
|
||||||
vol.Optional(CONF_NAME): cv.string,
|
|
||||||
vol.Optional(CONF_CURRENCY): cv.string,
|
|
||||||
}
|
|
||||||
),
|
|
||||||
cv.has_at_least_one_key(CONF_URL, CONF_ID),
|
|
||||||
)
|
|
||||||
|
|
||||||
_ITEMS_SCHEMA = vol.Schema([_ITEM_SCHEMA])
|
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|
||||||
{vol.Required(CONF_ITEMS): _ITEMS_SCHEMA, vol.Required(CONF_CURRENCY): cv.string}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
|
||||||
"""Set up the Gearbest sensor."""
|
|
||||||
|
|
||||||
currency = config.get(CONF_CURRENCY)
|
|
||||||
|
|
||||||
sensors = []
|
|
||||||
items = config.get(CONF_ITEMS)
|
|
||||||
|
|
||||||
converter = CurrencyConverter()
|
|
||||||
converter.update()
|
|
||||||
|
|
||||||
for item in items:
|
|
||||||
try:
|
|
||||||
sensors.append(GearbestSensor(converter, item, currency))
|
|
||||||
except ValueError as exc:
|
|
||||||
_LOGGER.error(exc)
|
|
||||||
|
|
||||||
def currency_update(event_time):
|
|
||||||
"""Update currency list."""
|
|
||||||
converter.update()
|
|
||||||
|
|
||||||
track_time_interval(hass, currency_update, MIN_TIME_BETWEEN_CURRENCY_UPDATES)
|
|
||||||
|
|
||||||
add_entities(sensors, True)
|
|
||||||
|
|
||||||
|
|
||||||
class GearbestSensor(Entity):
|
|
||||||
"""Implementation of the sensor."""
|
|
||||||
|
|
||||||
def __init__(self, converter, item, currency):
|
|
||||||
"""Initialize the sensor."""
|
|
||||||
|
|
||||||
self._name = item.get(CONF_NAME)
|
|
||||||
self._parser = GearbestParser()
|
|
||||||
self._parser.set_currency_converter(converter)
|
|
||||||
self._item = self._parser.load(
|
|
||||||
item.get(CONF_ID), item.get(CONF_URL), item.get(CONF_CURRENCY, currency)
|
|
||||||
)
|
|
||||||
if self._item is None:
|
|
||||||
raise ValueError("id and url could not be resolved")
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the item."""
|
|
||||||
return self._name if self._name is not None else self._item.name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
"""Return the icon for the frontend."""
|
|
||||||
return ICON
|
|
||||||
|
|
||||||
@property
|
|
||||||
def state(self):
|
|
||||||
"""Return the price of the selected product."""
|
|
||||||
return self._item.price
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unit_of_measurement(self):
|
|
||||||
"""Return the currency."""
|
|
||||||
return self._item.currency
|
|
||||||
|
|
||||||
@property
|
|
||||||
def entity_picture(self):
|
|
||||||
"""Return the image."""
|
|
||||||
return self._item.image
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_state_attributes(self):
|
|
||||||
"""Return the state attributes."""
|
|
||||||
attrs = {
|
|
||||||
"name": self._item.name,
|
|
||||||
"description": self._item.description,
|
|
||||||
"currency": self._item.currency,
|
|
||||||
"url": self._item.url,
|
|
||||||
}
|
|
||||||
return attrs
|
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
|
||||||
def update(self):
|
|
||||||
"""Get the latest price from gearbest and updates the state."""
|
|
||||||
self._item.update()
|
|
@ -612,9 +612,6 @@ gTTS-token==1.1.3
|
|||||||
# homeassistant.components.garmin_connect
|
# homeassistant.components.garmin_connect
|
||||||
garminconnect==0.1.13
|
garminconnect==0.1.13
|
||||||
|
|
||||||
# homeassistant.components.gearbest
|
|
||||||
gearbest_parser==1.0.7
|
|
||||||
|
|
||||||
# homeassistant.components.geizhals
|
# homeassistant.components.geizhals
|
||||||
geizhals==0.0.9
|
geizhals==0.0.9
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user