Skip to content

Adding USCIS component#13764

Merged
balloob merged 8 commits intohome-assistant:devfrom
meauxt:uscis
Apr 14, 2018
Merged

Adding USCIS component#13764
balloob merged 8 commits intohome-assistant:devfrom
meauxt:uscis

Conversation

@meauxt
Copy link
Copy Markdown
Contributor

@meauxt meauxt commented Apr 8, 2018

Description:

This component will fetch the lastest status on case from USCIS on daily basis

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#5138>

Example entry for configuration.yaml (if applicable):

sensor:
  - platform: uscis
    case_id: case_number
    friendly_name: optionalname

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
    • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New dependencies are only imported inside functions that use them (example).
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

APP_RECEIPT_NUM = "appReceiptNum"
INIT_CASE_SEARCH = "initCaseSearch"
CASE_STATUS = "CHECK STATUS"
UPDATE_TEXT_XPATH = "/html/body/div[2]/form/div/div[1]" \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too much protocol specific information and should be extracted into an external package.

@balloob
Copy link
Copy Markdown
Member

balloob commented Apr 9, 2018

Did you know that you can signup for a USCIS account and get notified by email/text of changes to your case?

Also, we should check in the terms of the USCIS if they allow being scraped. If not, we should not merge this.

@meauxt
Copy link
Copy Markdown
Contributor Author

meauxt commented Apr 9, 2018

@balloob I updated the component to use uscisstatus package.. also we check did check about the USCIS website term "Information presented on this WWW site is considered public information and may be distributed or copied. ".. i think it should be ready to merge

else:
_LOGGER.error("Setup USCIS Sensor Fail"
" check if your Case ID is Valid")
return
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary return.

"""Using Request to access USCIS website and fetch data."""
import uscisstatus
try:
status, date = uscisstatus.get_case_status(self._case_id)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine because it's a first version, but generally speaking returning a tuple will suck if you want to extend the returned data in the future. Namedtuples are your friend.

status, date = uscisstatus.get_case_status(self._case_id)
self._attributes = {
self.CURRENT_STATUS: status,
self.LAST_CASE_UPDATE: date
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already stored as state so shouldn't be an attribute.

@meauxt
Copy link
Copy Markdown
Contributor Author

meauxt commented Apr 9, 2018

@balloob changes has been made

"""Return the state attributes."""
return self._attributes

@Throttle(HOURS_TO_UPDATE)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you call the const MIN_TIME_BETWEEN_UPDATES and move the declaration to the top of the component? Just to be in sync with other sensors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did name it like this because timedelta has hour=24so i thought would be better to have it as HOUR_TO_UPDATE instead but if you still think it's better to rename it just let me know @syssi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meauxt We use MIN_TIME_BETWEEN_UPDATES everywhere and that can accommodate any time units (hours, minutes, seconds). It may be better, for the sake of consistency, to use the same label.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@syssi @arsaboo I did update the name of the the variable, Thank you!

self._attributes = {
self.CURRENT_STATUS: status['status']
}
self._state = status['date']
Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Contributor

@arsaboo arsaboo Apr 10, 2018

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 status is 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.

@balloob balloob merged commit 99ded8a into home-assistant:dev Apr 14, 2018
@balloob balloob mentioned this pull request Apr 27, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Jul 26, 2018
@ghost ghost removed the platform: sensor.uscis label Mar 21, 2019
@ghost ghost added the integration: uscis label Mar 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants