Get MyStrom device state before checking support#96004
Conversation
|
Hey there @fabaff, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
| def _get_mystrom_bulb(host: str, mac: str) -> MyStromBulb: | ||
| return MyStromBulb(host, mac) | ||
|
|
||
|
|
||
| def _get_mystrom_switch(host: str) -> MyStromSwitch: | ||
| return MyStromSwitch(host) |
There was a problem hiding this comment.
I currently use this method to be able to inject mocks in the tests. Any other method would be preferred!
There was a problem hiding this comment.
why do you need to make it a function instead of calling constructor right away like it was ?
There was a problem hiding this comment.
Because I want to inject a mock in the tests and I could not figure out how to patch a constructor call. (the mock is now used to mock the behaviour of the external library better, since the current tests arent representing this well)
| await device.get_state() | ||
| except MyStromConnectionError as err: | ||
| _LOGGER.error("No route to myStrom plug: %s", info["ip"]) | ||
| raise ConfigEntryNotReady() from err |
There was a problem hiding this comment.
I don't see this happening anymore ? This is important logic to make sure we retry if we cannot connect.
Proposed change
I checked the code in the library (wasn't updated since the config flow), and
device.bulb_typeis not set, untildevice.get_state()is called. Which was done in this code, but only after we check for compatibility.Type of change
Additional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.To help with the load of incoming pull requests: