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

Add support for sensors from Flu Near You #18136

Merged
merged 4 commits into from Nov 9, 2018

Conversation

Projects
None yet
4 participants
@bachya
Contributor

bachya commented Nov 3, 2018

Description:

This PR adds support for sensors from Flu Near You:

  • Number of user-reported symptoms near a latitude/longitude (no symptoms, flu, flu-like, avian flu, dengue fever, and leptospirosis)
  • Total number of user-reported symptoms of disease
  • CDC status for the state contained within that latitude/longitude

Related issue (if applicable): N/A

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

Example entry for configuration.yaml (if applicable):

sensor:
  - platform: flunearyou

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 are only imported inside functions that use them (example).
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

@bachya bachya self-assigned this Nov 3, 2018

@wafflebot wafflebot bot added the in progress label Nov 3, 2018

@bachya bachya referenced this pull request Nov 3, 2018

Merged

Add docs for Flu Near You #7345

2 of 2 tasks complete
@amelchio

This is awesome. I had to look hard to find some small comments that you can consider :-)

In case you want to address my comments, I am not marking this as approved. But I am also fine with merging as is.

ATTR_ZIP_CODE = 'zip_code'
DEFAULT_ATTRIBUTION = 'Data provided by Flu Near You'
DEFAULT_SCAN_INTERVAL = timedelta(minutes=30)

This comment has been minimized.

@amelchio

amelchio Nov 8, 2018

Member

This makes your sensors update every 30 seconds (the sensor default) but new data will only be available every 30 minutes.

Consider naming this MIN_TIME_BETWEEN_UPDATES instead and lower it a bit.

Then set SCAN_INTERVAL to 30 minutes so Home Assistant actually only updates the sensor every 30 minutes.

client = await create_client(latitude, longitude, websession)
except FluNearYouError as err:
_LOGGER.error('There was an error while setting up: %s', err)
return False

This comment has been minimized.

@amelchio

amelchio Nov 8, 2018

Member

If you expect that it might work later (like when the network is back), you can raise PlatformNotReady.

This comment has been minimized.

@MartinHjelmare

MartinHjelmare Nov 8, 2018

Member

☝️ or just return. Nothing is checking this return value.

client = await create_client(latitude, longitude, websession)
except FluNearYouError as err:
_LOGGER.error('There was an error while setting up: %s', err)
return False

This comment has been minimized.

@MartinHjelmare

MartinHjelmare Nov 8, 2018

Member

☝️ or just return. Nothing is checking this return value.

if self._category == CATEGORY_CDC_REPORT:
data = self.fny.data[CATEGORY_CDC_REPORT]
self._attrs.update({
ATTR_REPORTED_DATE: data['week_date'],

This comment has been minimized.

@MartinHjelmare

MartinHjelmare Nov 8, 2018

Member

There will be a KeyError here if the data update errors.

elif self._category == CATEGORY_USER_REPORT:
data = self.fny.data[CATEGORY_USER_REPORT]
self._attrs.update({
ATTR_CITY: data['city'].split('(')[0],

This comment has been minimized.

@MartinHjelmare

MartinHjelmare Nov 8, 2018

Member

See above.

TYPE_USER_CHICK, TYPE_USER_DENGUE, TYPE_USER_FLU,
TYPE_USER_LEPTO, TYPE_USER_SYMPTOMS))
else:
self._state = data[self._kind]

This comment has been minimized.

@MartinHjelmare

MartinHjelmare Nov 8, 2018

Member

See above.

bachya added some commits Nov 3, 2018

@bachya bachya force-pushed the bachya:flunearyou branch from 3bd8fc8 to 1b049ab Nov 9, 2018

@bachya

This comment has been minimized.

Contributor

bachya commented Nov 9, 2018

Thanks, @amelchio and @MartinHjelmare! 😄

@MartinHjelmare

Nice!

@MartinHjelmare

This comment has been minimized.

Member

MartinHjelmare commented Nov 9, 2018

Can be merged when build passes.

@bachya bachya merged commit f971309 into home-assistant:dev Nov 9, 2018

4 checks passed

Hound No violations found. Woof!
WIP ready for review
Details
cla-bot Everyone involved has signed the CLA
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@wafflebot wafflebot bot removed the in progress label Nov 9, 2018

@bachya bachya deleted the bachya:flunearyou branch Nov 9, 2018

zxdavb added a commit to zxdavb/home-assistant that referenced this pull request Nov 13, 2018

Add support for sensors from Flu Near You (home-assistant#18136)
* Add support for sensors from Flu Near You

* Added sensor for total reports with symptoms

* Member comments

* Member comments

@balloob balloob referenced this pull request Nov 29, 2018

Merged

0.83 #18776

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment