Add reboot and shutdown service to synology_dsm#42697
Add reboot and shutdown service to synology_dsm#42697Quentame merged 4 commits intohome-assistant:devfrom
Conversation
|
open todos for me:
|
223c150 to
2a62284
Compare
2a62284 to
18bcc0b
Compare
18bcc0b to
d141093
Compare
Quentame
left a comment
There was a problem hiding this comment.
Some questions otherwise seems nice.
|
@Quentame are there any open concerns from your side about this PR? |
|
Sorry for being so long, at first I would like to test, even if everything looks pretty nice. Then, I got some days off and I felt the need to give a break at code. |
|
ahhh ... it's ok 😉 you don't owe me an explanation 😉 |
* 'dev' of https://github.com/home-assistant/core: (552 commits) Use media player image proxy for roku media browser (home-assistant#43070) Add Shelly support for REST sensors (home-assistant#40429) Add system health section for the Supervisor (home-assistant#43074) Simplify distance conversion (home-assistant#43107) Add initial rest query params (home-assistant#42198) Bump pycsspeechtts to 1.0.4 (home-assistant#43105) Bump greeclimate to 0.9.6 (home-assistant#43106) Add reboot and shutdown service to synology_dsm (home-assistant#42697) Bump up ZHA dependencies (home-assistant#43104) Modify wait timeout in stream (home-assistant#42794) Bumped version to 0.117.6 Fix Plex auth issues by setting header (home-assistant#43081) Bump gTTS-token to 1.1.4 (home-assistant#43015) Bump pwmled to v1.6.7 (home-assistant#42903) Remove unneeded state restoration of the physical device in rpi_gpio_pwm integration (home-assistant#42804) Update frontend to 20201111.0 (home-assistant#43101) Show media progress in sisyphus (home-assistant#42996) Use internal url for Squeezebox if possible (home-assistant#43089) Add watchdog to reset nest subscriber (home-assistant#43034) Bump hatasmota to 0.0.29 (home-assistant#43013) ...
MartinHjelmare
left a comment
There was a problem hiding this comment.
Please address the comments in a new PR. Thanks!
| if not self.system: | ||
| _LOGGER.debug("async_reboot - System API not ready: %s", self) | ||
| return | ||
| self._hass.async_add_executor_job(self.system.reboot) |
There was a problem hiding this comment.
Why do we not await this executor job?
| await api.async_setup() | ||
| except SynologyDSMRequestException as err: | ||
| except (SynologyDSMLoginFailedException, SynologyDSMRequestException) as err: | ||
| _LOGGER.debug("async_setup_entry - Unable to connect to DSM: %s", str(err)) |
There was a problem hiding this comment.
We start logging messages with capital letter.
There was a problem hiding this comment.
We don't need to copy exceptions to string when logging them. They have a __str__ magic method already.
|
|
||
| async def service_handler(call: ServiceCall): | ||
| """Handle service call.""" | ||
| _LOGGER.debug( |
There was a problem hiding this comment.
This is already logged by the core.
| await dsm_api.system.shutdown() | ||
|
|
||
| for service in SERVICES: | ||
| _LOGGER.debug( |
There was a problem hiding this comment.
Logging the services we register seems not needed. There's no variation.
| ) | ||
| return | ||
|
|
||
| _LOGGER.info("%s DSM with serial %s", call.service, serial) |
| await self._hass.async_add_executor_job( | ||
| self.dsm.update, self._with_information | ||
| ) | ||
| async_dispatcher_send(self._hass, self.signal_sensor_update) |
There was a problem hiding this comment.
Please only wrap the line that can raise in the try... except block.
| assert config_entry.options[CONF_TIMEOUT] == 30 | ||
|
|
||
|
|
||
| async def test_services_registered(hass: HomeAssistantType): |
There was a problem hiding this comment.
This test should not be part of the config flow tests. It should move to a test_init.py module.
| async def test_services_registered(hass: HomeAssistantType): | ||
| """Test if all services are registered.""" | ||
| with patch( | ||
| "homeassistant.core.ServiceRegistry.async_register", return_value=Mock(True) |
There was a problem hiding this comment.
Don't patch the core. Set up the integration and check that the services are registered in the service registry.
| CONF_PASSWORD: PASSWORD, | ||
| }, | ||
| ) | ||
| await _async_setup_services(hass) |
There was a problem hiding this comment.
Don't interact with integration details in the tests.
https://developers.home-assistant.io/docs/development_testing#writing-tests-for-integrations
Proposed change
This PR make use of new features in python-synology lib v1.0.0 and add services to reboot and shutdown a DSM.
Rebase will be done, as soon #42539 is merged.
As side effect #41701 will be fixed.
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.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: