Skip to content

Add reboot and shutdown service to synology_dsm#42697

Merged
Quentame merged 4 commits intohome-assistant:devfrom
mib1185:synology-dsm_device-actions
Nov 11, 2020
Merged

Add reboot and shutdown service to synology_dsm#42697
Quentame merged 4 commits intohome-assistant:devfrom
mib1185:synology-dsm_device-actions

Conversation

@mib1185
Copy link
Copy Markdown
Member

@mib1185 mib1185 commented Nov 1, 2020

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

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

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

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@mib1185
Copy link
Copy Markdown
Member Author

mib1185 commented Nov 1, 2020

open todos for me:

@mib1185 mib1185 force-pushed the synology-dsm_device-actions branch 3 times, most recently from 223c150 to 2a62284 Compare November 1, 2020 21:03
@mib1185 mib1185 marked this pull request as ready for review November 1, 2020 22:04
@Quentame Quentame self-requested a review November 2, 2020 08:50
@mib1185 mib1185 force-pushed the synology-dsm_device-actions branch from 2a62284 to 18bcc0b Compare November 2, 2020 21:22
@mib1185 mib1185 force-pushed the synology-dsm_device-actions branch from 18bcc0b to d141093 Compare November 2, 2020 21:29
Copy link
Copy Markdown
Member

@Quentame Quentame left a comment

Choose a reason for hiding this comment

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

Some questions otherwise seems nice.

Comment thread homeassistant/components/synology_dsm/__init__.py
Comment thread homeassistant/components/synology_dsm/__init__.py Outdated
Comment thread homeassistant/components/synology_dsm/__init__.py Outdated
Comment thread homeassistant/components/synology_dsm/__init__.py
Comment thread tests/components/synology_dsm/test_config_flow.py Outdated
Comment thread homeassistant/components/synology_dsm/__init__.py Outdated
Comment thread homeassistant/components/synology_dsm/services.yaml Outdated
Comment thread homeassistant/components/synology_dsm/services.yaml Outdated
Comment thread homeassistant/components/synology_dsm/services.yaml Outdated
Comment thread homeassistant/components/synology_dsm/__init__.py
@mib1185 mib1185 requested a review from Quentame November 3, 2020 00:11
@mib1185
Copy link
Copy Markdown
Member Author

mib1185 commented Nov 8, 2020

@Quentame are there any open concerns from your side about this PR?
I really don't want to annoy you, but would like to complete this PR 😉

Copy link
Copy Markdown
Member

@Quentame Quentame left a comment

Choose a reason for hiding this comment

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

LGMT

@Quentame Quentame merged commit dbe89c1 into home-assistant:dev Nov 11, 2020
@Quentame
Copy link
Copy Markdown
Member

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.
But hey !
I'm back 😉

@mib1185
Copy link
Copy Markdown
Member Author

mib1185 commented Nov 11, 2020

ahhh ... it's ok 😉 you don't owe me an explanation 😉
But yeah, it's nice to see you again here 🥳

KJonline pushed a commit to Pyhass/core that referenced this pull request Nov 11, 2020
* '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)
  ...
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.

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)
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.

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))
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.

We start logging messages with capital letter.

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.

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(
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 is already logged by the core.

await dsm_api.system.shutdown()

for service in SERVICES:
_LOGGER.debug(
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.

Logging the services we register seems not needed. There's no variation.

)
return

_LOGGER.info("%s DSM with serial %s", call.service, serial)
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.

Max debug level.

await self._hass.async_add_executor_job(
self.dsm.update, self._with_information
)
async_dispatcher_send(self._hass, self.signal_sensor_update)
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.

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):
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 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)
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 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)
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.

@github-actions github-actions Bot locked and limited conversation to collaborators Nov 13, 2020
@mib1185 mib1185 deleted the synology-dsm_device-actions branch November 13, 2020 17:10
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.

SynologyDSM shows all unavailable after a schedule power down/up

4 participants