Hydroquebec component use now asyncio#10795
Conversation
91d3be6 to
570f0b6
Compare
570f0b6 to
6352093
Compare
MartinHjelmare
left a comment
There was a problem hiding this comment.
Two minor comments. Otherwise looks good.
There was a problem hiding this comment.
Rename add_devices to async_add_devices.
6352093 to
1889034
Compare
There was a problem hiding this comment.
undefined name 'aasync_add_devices'
There was a problem hiding this comment.
this error makes me wonder if you tested your code? 🤔
There was a problem hiding this comment.
I checked the box on the first commit, before updating this line...
But as always, quick patch, bad patch ...
There was a problem hiding this comment.
This needs to be an async_update
There was a problem hiding this comment.
@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_ ?
There was a problem hiding this comment.
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.
1889034 to
4f5198f
Compare
4f5198f to
29d0b57
Compare
25f2663 to
6199663
Compare
|
If you add tests please remove |
6199663 to
a43ec72
Compare
|
@andrey-git thanks ! It's my first tests in HASS ... |
a43ec72 to
8a7ee36
Compare
There was a problem hiding this comment.
line too long (81 > 79 characters)
8a7ee36 to
c999f40
Compare
| def fetch_data(self): | ||
| """Return fake fetching data.""" | ||
| if hasattr(self, 'data_fetched'): | ||
| raise PyHydroQuebecErrorMock("Fake Error") |
There was a problem hiding this comment.
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.
| pytest-timeout>=1.2.0 | ||
| pytest-catchlog>=1.2.2 | ||
| pytest-sugar>=0.7.1 | ||
| pytest-asyncio>=0.6.0 |
There was a problem hiding this comment.
I don't think you need new test requirements.
| ], | ||
| } | ||
| } | ||
| ret = yield from hydroquebec.async_setup_platform(hass, config, |
There was a problem hiding this comment.
Since you set up the component below, you should not set up the platform here.
|
|
||
|
|
||
| @asyncio.coroutine | ||
| def test_hydroquebec_sensor_2(hass): |
There was a problem hiding this comment.
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.
70f849f to
3041dbe
Compare
3041dbe to
77c4f43
Compare
|
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: |
There was a problem hiding this comment.
This can't happen here, since you already catch this error in HydroquebecData._fetch_data.
There was a problem hiding this comment.
local variable 'ret' is assigned to but never used
There was a problem hiding this comment.
local variable 'ret' is assigned to but never used
8baa0da to
aa9dcb2
Compare
There was a problem hiding this comment.
This isn't used anymore I think?
There was a problem hiding this comment.
You could subclass HydroQuebecClientMock, instead of writing the whole class again.
aa9dcb2 to
9051ac8
Compare
|
@MartinHjelmare changes done |
There was a problem hiding this comment.
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.
9051ac8 to
045337e
Compare
Description:
Hydroquebec component use now asyncio
This also update pyhydroquebec version
Checklist:
If user exposed functionality or configuration variables are added/changed:
toxrun successfully. Your PR cannot be merged unless tests passREQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py.