mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Allow synology_dsm configuration to specify a host name (#36305)
* Allow configuration to specify a host name. This will default to "synology", so the sensors would be named sensor.synology_... which is the original implementation. By specifying a name, which is required for multiple synology hosts, you can then have sensor.hostA_... and sensor.hostB_... * Get the base name for the sensors from the Synology DSM hostname * Don't need the name for the config * Added missing import * Fixed another typo * Removed definition of unused BASE_NAME * Removed end of line to revert * Moved for ordering
This commit is contained in:
parent
fcef259021
commit
95563e04e8
@ -8,6 +8,7 @@ from synology_dsm import SynologyDSM
|
|||||||
from synology_dsm.api.core.security import SynoCoreSecurity
|
from synology_dsm.api.core.security import SynoCoreSecurity
|
||||||
from synology_dsm.api.core.utilization import SynoCoreUtilization
|
from synology_dsm.api.core.utilization import SynoCoreUtilization
|
||||||
from synology_dsm.api.dsm.information import SynoDSMInformation
|
from synology_dsm.api.dsm.information import SynoDSMInformation
|
||||||
|
from synology_dsm.api.dsm.network import SynoDSMNetwork
|
||||||
from synology_dsm.api.storage.storage import SynoStorage
|
from synology_dsm.api.storage.storage import SynoStorage
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -35,7 +36,6 @@ from homeassistant.helpers.event import async_track_time_interval
|
|||||||
from homeassistant.helpers.typing import HomeAssistantType
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
BASE_NAME,
|
|
||||||
CONF_VOLUMES,
|
CONF_VOLUMES,
|
||||||
DEFAULT_SCAN_INTERVAL,
|
DEFAULT_SCAN_INTERVAL,
|
||||||
DEFAULT_SSL,
|
DEFAULT_SSL,
|
||||||
@ -219,6 +219,7 @@ class SynoApi:
|
|||||||
# DSM APIs
|
# DSM APIs
|
||||||
self.dsm: SynologyDSM = None
|
self.dsm: SynologyDSM = None
|
||||||
self.information: SynoDSMInformation = None
|
self.information: SynoDSMInformation = None
|
||||||
|
self.network: SynoDSMNetwork = None
|
||||||
self.security: SynoCoreSecurity = None
|
self.security: SynoCoreSecurity = None
|
||||||
self.storage: SynoStorage = None
|
self.storage: SynoStorage = None
|
||||||
self.utilisation: SynoCoreUtilization = None
|
self.utilisation: SynoCoreUtilization = None
|
||||||
@ -308,6 +309,7 @@ class SynoApi:
|
|||||||
def _fetch_device_configuration(self):
|
def _fetch_device_configuration(self):
|
||||||
"""Fetch initial device config."""
|
"""Fetch initial device config."""
|
||||||
self.information = self.dsm.information
|
self.information = self.dsm.information
|
||||||
|
self.network = self.dsm.network
|
||||||
|
|
||||||
if self._with_security:
|
if self._with_security:
|
||||||
self.security = self.dsm.security
|
self.security = self.dsm.security
|
||||||
@ -339,7 +341,7 @@ class SynologyDSMEntity(Entity):
|
|||||||
self._api = api
|
self._api = api
|
||||||
self._api_key = entity_type.split(":")[0]
|
self._api_key = entity_type.split(":")[0]
|
||||||
self.entity_type = entity_type.split(":")[-1]
|
self.entity_type = entity_type.split(":")[-1]
|
||||||
self._name = f"{BASE_NAME} {entity_info[ENTITY_NAME]}"
|
self._name = f"{api.network.hostname} {entity_info[ENTITY_NAME]}"
|
||||||
self._class = entity_info[ENTITY_CLASS]
|
self._class = entity_info[ENTITY_CLASS]
|
||||||
self._enable_default = entity_info[ENTITY_ENABLE]
|
self._enable_default = entity_info[ENTITY_ENABLE]
|
||||||
self._icon = entity_info[ENTITY_ICON]
|
self._icon = entity_info[ENTITY_ICON]
|
||||||
@ -456,7 +458,7 @@ class SynologyDSMDeviceEntity(SynologyDSMEntity):
|
|||||||
self._device_model = disk["model"].strip()
|
self._device_model = disk["model"].strip()
|
||||||
self._device_firmware = disk["firm"]
|
self._device_firmware = disk["firm"]
|
||||||
self._device_type = disk["diskType"]
|
self._device_type = disk["diskType"]
|
||||||
self._name = f"{BASE_NAME} {self._device_name} {entity_info[ENTITY_NAME]}"
|
self._name = f"{self._api.network.hostname} {self._device_name} {entity_info[ENTITY_NAME]}"
|
||||||
self._unique_id += f"_{self._device_id}"
|
self._unique_id += f"_{self._device_id}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -14,8 +14,6 @@ from homeassistant.const import (
|
|||||||
DOMAIN = "synology_dsm"
|
DOMAIN = "synology_dsm"
|
||||||
PLATFORMS = ["binary_sensor", "sensor"]
|
PLATFORMS = ["binary_sensor", "sensor"]
|
||||||
|
|
||||||
BASE_NAME = "Synology"
|
|
||||||
|
|
||||||
# Entry keys
|
# Entry keys
|
||||||
SYNO_API = "syno_api"
|
SYNO_API = "syno_api"
|
||||||
UNDO_UPDATE_LISTENER = "undo_update_listener"
|
UNDO_UPDATE_LISTENER = "undo_update_listener"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user