Skip to content

Hydroquebec component use now asyncio#10795

Merged
MartinHjelmare merged 5 commits into
home-assistant:devfrom
titilambert:hydroquebec
Dec 17, 2017
Merged

Hydroquebec component use now asyncio#10795
MartinHjelmare merged 5 commits into
home-assistant:devfrom
titilambert:hydroquebec

Conversation

@titilambert
Copy link
Copy Markdown
Contributor

@titilambert titilambert commented Nov 25, 2017

Description:

Hydroquebec component use now asyncio
This also update pyhydroquebec version

Checklist:

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

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

'time' imported but unused

Copy link
Copy Markdown
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.

Two minor comments. Otherwise looks good.

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.

Rename add_devices to async_add_devices.

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.

Same as above.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

undefined name 'aasync_add_devices'

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 error makes me wonder if you tested your code? 🤔

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 checked the box on the first commit, before updating this line...
But as always, quick patch, bad patch ...

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.

Fixed !

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 needs to be an async_update

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.

@balloob This is not the update method directly call by hass, this method is called by an other async_update method.
So my question is: do coroutine names have to start by async_ ?

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.

Good point! No they don't. Only the entity method needs to be named async_update for the code to work, if it's a coroutine. But for clarity it could be wise to have this method be called async_update too.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

'tempfile' imported but unused

@andrey-git
Copy link
Copy Markdown
Contributor

If you add tests please remove homeassistant/components/sensor/hydroquebec.py from coverageac

@titilambert
Copy link
Copy Markdown
Contributor Author

@andrey-git thanks ! It's my first tests in HASS ...

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (81 > 79 characters)

def fetch_data(self):
"""Return fake fetching data."""
if hasattr(self, 'data_fetched'):
raise PyHydroQuebecErrorMock("Fake Error")
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.

Don't do this here. Just patch the call that should error, and add a side effect that raises the error. Tests should also be totally isolated from each other.

Comment thread requirements_test.txt Outdated
pytest-timeout>=1.2.0
pytest-catchlog>=1.2.2
pytest-sugar>=0.7.1
pytest-asyncio>=0.6.0
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.

I don't think you need new test requirements.

],
}
}
ret = yield from hydroquebec.async_setup_platform(hass, config,
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.

Since you set up the component below, you should not set up the platform here.

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.

fixed



@asyncio.coroutine
def test_hydroquebec_sensor_2(hass):
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.

Name the test functions according to what they test. You don't need to include the module name in all of the test names, since that is assumed already.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

expected 1 blank line, found 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

'pytest' imported but unused

@titilambert
Copy link
Copy Markdown
Contributor Author

Ready for review, I hope this is the good one !

except requests.exceptions.HTTPError as error:
_LOGGER.error("Failt login: %s", error)
", ".join(contracts))
except BaseException as error:
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 can't happen here, since you already catch this error in HydroquebecData._fetch_data.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

local variable 'ret' is assigned to but never used

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

local variable 'ret' is assigned to but never used

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 isn't used anymore I think?

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.

You could subclass HydroQuebecClientMock, instead of writing the whole class again.

@titilambert
Copy link
Copy Markdown
Contributor Author

@MartinHjelmare changes done

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 test is missing an assertion. I think you should pass caplog here and assert that the text contains "Error on receive last Hydroquebec data...". With that this should be good to go.

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.

Fixed !

Copy link
Copy Markdown
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.

Thanks! Good work! 🎉

@MartinHjelmare MartinHjelmare merged commit 8742ce0 into home-assistant:dev Dec 17, 2017
@balloob balloob mentioned this pull request Jan 11, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Mar 30, 2018
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.

7 participants