-
-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Adding USCIS component #13764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Adding USCIS component #13764
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
610b329
Adding USCIS component
meauxt b4d376c
Adding Line after the class DOC
meauxt 1ef3fb2
Update : Extract USCIS logic code to Component
meauxt edf34b4
Update : Extract USCIS logic code to Component
meauxt a01695e
Adding CURRENT_STATUS
meauxt 74d077e
Change Error handling, remove date from attributes
meauxt 5199964
Update the Version for USCIS
meauxt ee480aa
Update uscis.py
meauxt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you return the date as state? The status looks like more important to me. I don't know USCIS. ;-) Could you provide some example output here?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syssi The date indicates last update. The actual
statusis quite verbose and beyond the 255 chars limit. More importantly, the status update text may not be very useful for automation. Here's an example of a status message:On March 8, 2018, we accepted the fingerprint fee for your Form I-485, Application to Register Permanent Residence or Adjust Status, Receipt Number SRCxyz. Our Texas Service Center location is working on your case. We mailed you a notice describing how we will process your case. Please follow the instructions in the notice. If you move, go to USCIS website to give us your new mailing address.