mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Remove deprecated usps integration (ADR-0004) (#26823)
This commit is contained in:
parent
2f277c4ea7
commit
38ad573b96
@ -692,7 +692,6 @@ omit =
|
|||||||
homeassistant/components/upc_connect/*
|
homeassistant/components/upc_connect/*
|
||||||
homeassistant/components/uptimerobot/binary_sensor.py
|
homeassistant/components/uptimerobot/binary_sensor.py
|
||||||
homeassistant/components/uscis/sensor.py
|
homeassistant/components/uscis/sensor.py
|
||||||
homeassistant/components/usps/*
|
|
||||||
homeassistant/components/vallox/*
|
homeassistant/components/vallox/*
|
||||||
homeassistant/components/vasttrafik/sensor.py
|
homeassistant/components/vasttrafik/sensor.py
|
||||||
homeassistant/components/velbus/__init__.py
|
homeassistant/components/velbus/__init__.py
|
||||||
|
@ -1,96 +0,0 @@
|
|||||||
"""Support for USPS packages and mail."""
|
|
||||||
from datetime import timedelta
|
|
||||||
import logging
|
|
||||||
|
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
from homeassistant.const import CONF_NAME, CONF_USERNAME, CONF_PASSWORD
|
|
||||||
from homeassistant.helpers import config_validation as cv, discovery
|
|
||||||
from homeassistant.util import Throttle
|
|
||||||
from homeassistant.util.dt import now
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
DOMAIN = "usps"
|
|
||||||
DATA_USPS = "data_usps"
|
|
||||||
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=30)
|
|
||||||
COOKIE = "usps_cookies.pickle"
|
|
||||||
CACHE = "usps_cache"
|
|
||||||
CONF_DRIVER = "driver"
|
|
||||||
|
|
||||||
USPS_TYPE = ["sensor", "camera"]
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
|
||||||
{
|
|
||||||
DOMAIN: vol.Schema(
|
|
||||||
{
|
|
||||||
vol.Required(CONF_USERNAME): cv.string,
|
|
||||||
vol.Required(CONF_PASSWORD): cv.string,
|
|
||||||
vol.Optional(CONF_NAME, default=DOMAIN): cv.string,
|
|
||||||
vol.Optional(CONF_DRIVER): cv.string,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
extra=vol.ALLOW_EXTRA,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
|
||||||
"""Use config values to set up a function enabling status retrieval."""
|
|
||||||
_LOGGER.warning(
|
|
||||||
"The usps 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"
|
|
||||||
)
|
|
||||||
|
|
||||||
conf = config[DOMAIN]
|
|
||||||
username = conf.get(CONF_USERNAME)
|
|
||||||
password = conf.get(CONF_PASSWORD)
|
|
||||||
name = conf.get(CONF_NAME)
|
|
||||||
driver = conf.get(CONF_DRIVER)
|
|
||||||
|
|
||||||
import myusps
|
|
||||||
|
|
||||||
try:
|
|
||||||
cookie = hass.config.path(COOKIE)
|
|
||||||
cache = hass.config.path(CACHE)
|
|
||||||
session = myusps.get_session(
|
|
||||||
username, password, cookie_path=cookie, cache_path=cache, driver=driver
|
|
||||||
)
|
|
||||||
except myusps.USPSError:
|
|
||||||
_LOGGER.exception("Could not connect to My USPS")
|
|
||||||
return False
|
|
||||||
|
|
||||||
hass.data[DATA_USPS] = USPSData(session, name)
|
|
||||||
|
|
||||||
for component in USPS_TYPE:
|
|
||||||
discovery.load_platform(hass, component, DOMAIN, {}, config)
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class USPSData:
|
|
||||||
"""Stores the data retrieved from USPS.
|
|
||||||
|
|
||||||
For each entity to use, acts as the single point responsible for fetching
|
|
||||||
updates from the server.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, session, name):
|
|
||||||
"""Initialize the data object."""
|
|
||||||
self.session = session
|
|
||||||
self.name = name
|
|
||||||
self.packages = []
|
|
||||||
self.mail = []
|
|
||||||
self.attribution = None
|
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
|
||||||
def update(self, **kwargs):
|
|
||||||
"""Fetch the latest info from USPS."""
|
|
||||||
import myusps
|
|
||||||
|
|
||||||
self.packages = myusps.get_packages(self.session)
|
|
||||||
self.mail = myusps.get_mail(self.session, now().date())
|
|
||||||
self.attribution = myusps.ATTRIBUTION
|
|
||||||
_LOGGER.debug("Mail, request date: %s, list: %s", now().date(), self.mail)
|
|
||||||
_LOGGER.debug("Package list: %s", self.packages)
|
|
@ -1,88 +0,0 @@
|
|||||||
"""Support for a camera made up of USPS mail images."""
|
|
||||||
from datetime import timedelta
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from homeassistant.components.camera import Camera
|
|
||||||
|
|
||||||
from . import DATA_USPS
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=10)
|
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
|
||||||
"""Set up USPS mail camera."""
|
|
||||||
if discovery_info is None:
|
|
||||||
return
|
|
||||||
|
|
||||||
usps = hass.data[DATA_USPS]
|
|
||||||
add_entities([USPSCamera(usps)])
|
|
||||||
|
|
||||||
|
|
||||||
class USPSCamera(Camera):
|
|
||||||
"""Representation of the images available from USPS."""
|
|
||||||
|
|
||||||
def __init__(self, usps):
|
|
||||||
"""Initialize the USPS camera images."""
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
self._usps = usps
|
|
||||||
self._name = self._usps.name
|
|
||||||
self._session = self._usps.session
|
|
||||||
|
|
||||||
self._mail_img = []
|
|
||||||
self._last_mail = None
|
|
||||||
self._mail_index = 0
|
|
||||||
self._mail_count = 0
|
|
||||||
|
|
||||||
self._timer = None
|
|
||||||
|
|
||||||
def camera_image(self):
|
|
||||||
"""Update the camera's image if it has changed."""
|
|
||||||
self._usps.update()
|
|
||||||
try:
|
|
||||||
self._mail_count = len(self._usps.mail)
|
|
||||||
except TypeError:
|
|
||||||
# No mail
|
|
||||||
return None
|
|
||||||
|
|
||||||
if self._usps.mail != self._last_mail:
|
|
||||||
# Mail items must have changed
|
|
||||||
self._mail_img = []
|
|
||||||
if len(self._usps.mail) >= 1:
|
|
||||||
self._last_mail = self._usps.mail
|
|
||||||
for article in self._usps.mail:
|
|
||||||
_LOGGER.debug("Fetching article image: %s", article)
|
|
||||||
img = self._session.get(article["image"]).content
|
|
||||||
self._mail_img.append(img)
|
|
||||||
|
|
||||||
try:
|
|
||||||
return self._mail_img[self._mail_index]
|
|
||||||
except IndexError:
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of this camera."""
|
|
||||||
return f"{self._name} mail"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def model(self):
|
|
||||||
"""Return date of mail as model."""
|
|
||||||
try:
|
|
||||||
return "Date: {}".format(str(self._usps.mail[0]["date"]))
|
|
||||||
except IndexError:
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""Update the mail image index periodically."""
|
|
||||||
return True
|
|
||||||
|
|
||||||
def update(self):
|
|
||||||
"""Update mail image index."""
|
|
||||||
if self._mail_index < (self._mail_count - 1):
|
|
||||||
self._mail_index += 1
|
|
||||||
else:
|
|
||||||
self._mail_index = 0
|
|
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"domain": "usps",
|
|
||||||
"name": "Usps",
|
|
||||||
"documentation": "https://www.home-assistant.io/components/usps",
|
|
||||||
"requirements": [
|
|
||||||
"myusps==1.3.2"
|
|
||||||
],
|
|
||||||
"dependencies": [],
|
|
||||||
"codeowners": []
|
|
||||||
}
|
|
@ -1,122 +0,0 @@
|
|||||||
"""Sensor for USPS packages."""
|
|
||||||
from collections import defaultdict
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from homeassistant.const import ATTR_ATTRIBUTION, ATTR_DATE
|
|
||||||
from homeassistant.helpers.entity import Entity
|
|
||||||
from homeassistant.util import slugify
|
|
||||||
from homeassistant.util.dt import now
|
|
||||||
|
|
||||||
from . import DATA_USPS
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
STATUS_DELIVERED = "delivered"
|
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
|
||||||
"""Set up the USPS platform."""
|
|
||||||
if discovery_info is None:
|
|
||||||
return
|
|
||||||
|
|
||||||
usps = hass.data[DATA_USPS]
|
|
||||||
add_entities([USPSPackageSensor(usps), USPSMailSensor(usps)], True)
|
|
||||||
|
|
||||||
|
|
||||||
class USPSPackageSensor(Entity):
|
|
||||||
"""USPS Package Sensor."""
|
|
||||||
|
|
||||||
def __init__(self, usps):
|
|
||||||
"""Initialize the sensor."""
|
|
||||||
self._usps = usps
|
|
||||||
self._name = self._usps.name
|
|
||||||
self._attributes = None
|
|
||||||
self._state = None
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the sensor."""
|
|
||||||
return f"{self._name} packages"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def state(self):
|
|
||||||
"""Return the state of the sensor."""
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
def update(self):
|
|
||||||
"""Update device state."""
|
|
||||||
self._usps.update()
|
|
||||||
status_counts = defaultdict(int)
|
|
||||||
for package in self._usps.packages:
|
|
||||||
status = slugify(package["primary_status"])
|
|
||||||
if status == STATUS_DELIVERED and package["delivery_date"] < now().date():
|
|
||||||
continue
|
|
||||||
status_counts[status] += 1
|
|
||||||
self._attributes = {ATTR_ATTRIBUTION: self._usps.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):
|
|
||||||
"""Return the icon to use in the frontend."""
|
|
||||||
return "mdi:package-variant-closed"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unit_of_measurement(self):
|
|
||||||
"""Return the unit of measurement of this entity, if any."""
|
|
||||||
return "packages"
|
|
||||||
|
|
||||||
|
|
||||||
class USPSMailSensor(Entity):
|
|
||||||
"""USPS Mail Sensor."""
|
|
||||||
|
|
||||||
def __init__(self, usps):
|
|
||||||
"""Initialize the sensor."""
|
|
||||||
self._usps = usps
|
|
||||||
self._name = self._usps.name
|
|
||||||
self._attributes = None
|
|
||||||
self._state = None
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the sensor."""
|
|
||||||
return f"{self._name} mail"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def state(self):
|
|
||||||
"""Return the state of the sensor."""
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
def update(self):
|
|
||||||
"""Update device state."""
|
|
||||||
self._usps.update()
|
|
||||||
if self._usps.mail is not None:
|
|
||||||
self._state = len(self._usps.mail)
|
|
||||||
else:
|
|
||||||
self._state = 0
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_state_attributes(self):
|
|
||||||
"""Return the state attributes."""
|
|
||||||
attr = {}
|
|
||||||
attr[ATTR_ATTRIBUTION] = self._usps.attribution
|
|
||||||
try:
|
|
||||||
attr[ATTR_DATE] = str(self._usps.mail[0]["date"])
|
|
||||||
except IndexError:
|
|
||||||
pass
|
|
||||||
return attr
|
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
"""Icon to use in the frontend."""
|
|
||||||
return "mdi:mailbox"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unit_of_measurement(self):
|
|
||||||
"""Return the unit of measurement of this entity, if any."""
|
|
||||||
return "pieces"
|
|
@ -836,9 +836,6 @@ mychevy==1.2.0
|
|||||||
# homeassistant.components.mycroft
|
# homeassistant.components.mycroft
|
||||||
mycroftapi==2.0
|
mycroftapi==2.0
|
||||||
|
|
||||||
# homeassistant.components.usps
|
|
||||||
myusps==1.3.2
|
|
||||||
|
|
||||||
# homeassistant.components.n26
|
# homeassistant.components.n26
|
||||||
n26==0.2.7
|
n26==0.2.7
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user