Skip to content
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
Merged

Conversation

bachya
Copy link
Contributor

@bachya 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.

Copy link
Contributor

@amelchio amelchio left a comment

Choose a reason for hiding this comment

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

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

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
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Member

Choose a reason for hiding this comment

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

☝️ 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
Copy link
Member

Choose a reason for hiding this comment

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

☝️ 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'],
Copy link
Member

Choose a reason for hiding this comment

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

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],
Copy link
Member

Choose a reason for hiding this comment

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

See above.

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

Choose a reason for hiding this comment

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

See above.

@bachya
Copy link
Contributor Author

bachya commented Nov 9, 2018

Thanks, @amelchio and @MartinHjelmare! 😄

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Nice!

@MartinHjelmare
Copy link
Member

Can be merged when build passes.

@bachya bachya merged commit f971309 into home-assistant:dev Nov 9, 2018
@ghost ghost removed the in progress label Nov 9, 2018
@bachya bachya deleted the flunearyou branch November 9, 2018 16:12
@balloob balloob mentioned this pull request Nov 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants