mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Remove deprecated ups integration (ADR-0004) (#26824)
This commit is contained in:
parent
5a4a3e17cc
commit
2f277c4ea7
@ -690,7 +690,6 @@ omit =
|
||||
homeassistant/components/upcloud/*
|
||||
homeassistant/components/upnp/*
|
||||
homeassistant/components/upc_connect/*
|
||||
homeassistant/components/ups/sensor.py
|
||||
homeassistant/components/uptimerobot/binary_sensor.py
|
||||
homeassistant/components/uscis/sensor.py
|
||||
homeassistant/components/usps/*
|
||||
|
@ -1 +0,0 @@
|
||||
"""The ups component."""
|
@ -1,10 +0,0 @@
|
||||
{
|
||||
"domain": "ups",
|
||||
"name": "Ups",
|
||||
"documentation": "https://www.home-assistant.io/components/ups",
|
||||
"requirements": [
|
||||
"upsmychoice==1.0.6"
|
||||
],
|
||||
"dependencies": [],
|
||||
"codeowners": []
|
||||
}
|
@ -1,126 +0,0 @@
|
||||
"""Sensor for UPS packages."""
|
||||
import logging
|
||||
from collections import defaultdict
|
||||
from datetime import timedelta
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
CONF_NAME,
|
||||
CONF_PASSWORD,
|
||||
CONF_SCAN_INTERVAL,
|
||||
CONF_USERNAME,
|
||||
)
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle, slugify
|
||||
from homeassistant.util.dt import now, parse_date
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN = "ups"
|
||||
COOKIE = "upsmychoice_cookies.pickle"
|
||||
ICON = "mdi:package-variant-closed"
|
||||
STATUS_DELIVERED = "delivered"
|
||||
|
||||
SCAN_INTERVAL = timedelta(seconds=1800)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Optional(CONF_NAME): cv.string,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the UPS platform."""
|
||||
import upsmychoice
|
||||
|
||||
_LOGGER.warning(
|
||||
"The ups integration is deprecated and will be removed "
|
||||
"in Home Assistant 0.100.0. For more information see ADR-0004:"
|
||||
"https://github.com/home-assistant/architecture/blob/master/adr/0004-webscraping.md"
|
||||
)
|
||||
|
||||
try:
|
||||
cookie = hass.config.path(COOKIE)
|
||||
session = upsmychoice.get_session(
|
||||
config.get(CONF_USERNAME), config.get(CONF_PASSWORD), cookie_path=cookie
|
||||
)
|
||||
except upsmychoice.UPSError:
|
||||
_LOGGER.exception("Could not connect to UPS My Choice")
|
||||
return False
|
||||
|
||||
add_entities(
|
||||
[
|
||||
UPSSensor(
|
||||
session,
|
||||
config.get(CONF_NAME),
|
||||
config.get(CONF_SCAN_INTERVAL, SCAN_INTERVAL),
|
||||
)
|
||||
],
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
class UPSSensor(Entity):
|
||||
"""UPS Sensor."""
|
||||
|
||||
def __init__(self, session, name, interval):
|
||||
"""Initialize the sensor."""
|
||||
self._session = session
|
||||
self._name = name
|
||||
self._attributes = None
|
||||
self._state = None
|
||||
self.update = Throttle(interval)(self._update)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return self._name or DOMAIN
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this entity, if any."""
|
||||
return "packages"
|
||||
|
||||
def _update(self):
|
||||
"""Update device state."""
|
||||
import upsmychoice
|
||||
|
||||
status_counts = defaultdict(int)
|
||||
try:
|
||||
for package in upsmychoice.get_packages(self._session):
|
||||
status = slugify(package["status"])
|
||||
skip = (
|
||||
status == STATUS_DELIVERED
|
||||
and parse_date(package["delivery_date"]) < now().date()
|
||||
)
|
||||
if skip:
|
||||
continue
|
||||
status_counts[status] += 1
|
||||
except upsmychoice.UPSError:
|
||||
_LOGGER.error("Could not connect to UPS My Choice account")
|
||||
|
||||
self._attributes = {ATTR_ATTRIBUTION: upsmychoice.ATTRIBUTION}
|
||||
self._attributes.update(status_counts)
|
||||
self._state = sum(status_counts.values())
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
return self._attributes
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Icon to use in the frontend."""
|
||||
return ICON
|
@ -1913,9 +1913,6 @@ twilio==6.19.1
|
||||
# homeassistant.components.upcloud
|
||||
upcloud-api==0.4.3
|
||||
|
||||
# homeassistant.components.ups
|
||||
upsmychoice==1.0.6
|
||||
|
||||
# homeassistant.components.uscis
|
||||
uscisstatus==0.1.1
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user