Adding USCIS component (#13764)
* Adding USCIS component * Adding Line after the class DOC * Update : Extract USCIS logic code to Component * Update : Extract USCIS logic code to Component * Adding CURRENT_STATUS * Change Error handling, remove date from attributes * Update the Version for USCIS * Update uscis.py
This commit is contained in:
parent
c6c166645d
commit
99ded8a0a6
3 changed files with 91 additions and 0 deletions
|
@ -675,6 +675,7 @@ omit =
|
|||
homeassistant/components/sensor/uber.py
|
||||
homeassistant/components/sensor/upnp.py
|
||||
homeassistant/components/sensor/ups.py
|
||||
homeassistant/components/sensor/uscis.py
|
||||
homeassistant/components/sensor/vasttrafik.py
|
||||
homeassistant/components/sensor/viaggiatreno.py
|
||||
homeassistant/components/sensor/waqi.py
|
||||
|
|
87
homeassistant/components/sensor/uscis.py
Normal file
87
homeassistant/components/sensor/uscis.py
Normal file
|
@ -0,0 +1,87 @@
|
|||
"""
|
||||
Support for USCIS Case Status.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/sensor.uscis/
|
||||
"""
|
||||
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.const import CONF_FRIENDLY_NAME
|
||||
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
REQUIREMENTS = ['uscisstatus==0.1.1']
|
||||
|
||||
DEFAULT_NAME = "USCIS"
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Optional(CONF_FRIENDLY_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Required('case_id'): cv.string,
|
||||
})
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setting the platform in HASS and Case Information."""
|
||||
uscis = UscisSensor(config['case_id'], config[CONF_FRIENDLY_NAME])
|
||||
uscis.update()
|
||||
if uscis.valid_case_id:
|
||||
add_devices([uscis])
|
||||
else:
|
||||
_LOGGER.error("Setup USCIS Sensor Fail"
|
||||
" check if your Case ID is Valid")
|
||||
|
||||
|
||||
class UscisSensor(Entity):
|
||||
"""USCIS Sensor will check case status on daily basis."""
|
||||
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(hours=24)
|
||||
|
||||
CURRENT_STATUS = "current_status"
|
||||
LAST_CASE_UPDATE = "last_update_date"
|
||||
|
||||
def __init__(self, case, name):
|
||||
"""Initialize the sensor."""
|
||||
self._state = None
|
||||
self._case_id = case
|
||||
self._attributes = None
|
||||
self.valid_case_id = None
|
||||
self._name = name
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
return self._attributes
|
||||
|
||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||
def update(self):
|
||||
"""Using Request to access USCIS website and fetch data."""
|
||||
import uscisstatus
|
||||
try:
|
||||
status = uscisstatus.get_case_status(self._case_id)
|
||||
self._attributes = {
|
||||
self.CURRENT_STATUS: status['status']
|
||||
}
|
||||
self._state = status['date']
|
||||
self.valid_case_id = True
|
||||
|
||||
except ValueError:
|
||||
_LOGGER("Please Check that you have valid USCIS case id")
|
||||
self.valid_case_id = False
|
|
@ -1268,6 +1268,9 @@ upcloud-api==0.4.2
|
|||
# homeassistant.components.sensor.ups
|
||||
upsmychoice==1.0.6
|
||||
|
||||
# homeassistant.components.sensor.uscis
|
||||
uscisstatus==0.1.1
|
||||
|
||||
# homeassistant.components.camera.uvc
|
||||
uvcclient==0.10.1
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue