Improve entity and device naming in Synology DSM (#69754)

This commit is contained in:
Michael 2022-04-23 07:57:39 +02:00 committed by GitHub
parent eccc8bf79d
commit ed8fe9963e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 20 deletions

View File

@ -249,13 +249,9 @@ class SynologyDSMBaseEntity(
self._attr_unique_id: str = ( self._attr_unique_id: str = (
f"{api.information.serial}_{description.api_key}:{description.key}" f"{api.information.serial}_{description.api_key}:{description.key}"
) )
self._attr_device_info = DeviceInfo(
@property
def device_info(self) -> DeviceInfo:
"""Return the device information."""
return DeviceInfo(
identifiers={(DOMAIN, self._api.information.serial)}, identifiers={(DOMAIN, self._api.information.serial)},
name="Synology NAS", name=self._api.network.hostname,
manufacturer="Synology", manufacturer="Synology",
model=self._api.information.model, model=self._api.information.model,
sw_version=self._api.information.version_string, sw_version=self._api.information.version_string,
@ -309,25 +305,22 @@ class SynologyDSMDeviceEntity(SynologyDSMBaseEntity):
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"{self._api.network.hostname} {self._device_name} {description.name}" self._attr_name = (
f"{self._api.network.hostname} ({self._device_name}) {description.name}"
) )
self._attr_unique_id += f"_{self._device_id}" self._attr_unique_id += f"_{self._device_id}"
self._attr_device_info = DeviceInfo(
@property
def available(self) -> bool:
"""Return True if entity is available."""
return self._api.storage # type: ignore [no-any-return]
@property
def device_info(self) -> DeviceInfo:
"""Return the device information."""
return DeviceInfo(
identifiers={(DOMAIN, f"{self._api.information.serial}_{self._device_id}")}, identifiers={(DOMAIN, f"{self._api.information.serial}_{self._device_id}")},
name=f"Synology NAS ({self._device_name} - {self._device_type})", name=f"{self._api.network.hostname} ({self._device_name})",
manufacturer=self._device_manufacturer, manufacturer=self._device_manufacturer,
model=self._device_model, model=self._device_model,
sw_version=self._device_firmware, sw_version=self._device_firmware,
via_device=(DOMAIN, self._api.information.serial), via_device=(DOMAIN, self._api.information.serial),
configuration_url=self._api.config_url, configuration_url=self._api.config_url,
) )
@property
def available(self) -> bool:
"""Return True if entity is available."""
return self._api.storage # type: ignore [no-any-return]

View File

@ -83,6 +83,10 @@ class SynoDSMSurveillanceHomeModeToggle(SynologyDSMBaseEntity, SwitchEntity):
super().__init__(api, coordinator, description) super().__init__(api, coordinator, description)
self._version = version self._version = version
self._attr_name = (
f"{self._api.network.hostname} Surveillance Station {description.name}"
)
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return the state.""" """Return the state."""
@ -125,7 +129,7 @@ class SynoDSMSurveillanceHomeModeToggle(SynologyDSMBaseEntity, SwitchEntity):
f"{self._api.information.serial}_{SynoSurveillanceStation.INFO_API_KEY}", f"{self._api.information.serial}_{SynoSurveillanceStation.INFO_API_KEY}",
) )
}, },
name="Surveillance Station", name=f"{self._api.network.hostname} Surveillance Station",
manufacturer="Synology", manufacturer="Synology",
model=self._api.information.model, model=self._api.information.model,
sw_version=self._version, sw_version=self._version,