From d7edb5b11c5b2cc2f3925425c5d581aa8b9922a1 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 28 Oct 2021 14:31:11 +0200 Subject: [PATCH] Use DeviceInfo in syncthru (#58581) Co-authored-by: epenet <epenet@users.noreply.github.com> --- homeassistant/components/syncthru/binary_sensor.py | 10 ++++++++-- homeassistant/components/syncthru/sensor.py | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/syncthru/binary_sensor.py b/homeassistant/components/syncthru/binary_sensor.py index 1c402fbf836..18780e9225e 100644 --- a/homeassistant/components/syncthru/binary_sensor.py +++ b/homeassistant/components/syncthru/binary_sensor.py @@ -1,4 +1,5 @@ """Support for Samsung Printers with SyncThru web interface.""" +from __future__ import annotations from pysyncthru import SyncThru, SyncthruState @@ -8,6 +9,7 @@ from homeassistant.components.binary_sensor import ( BinarySensorEntity, ) from homeassistant.const import CONF_NAME +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, DataUpdateCoordinator, @@ -63,9 +65,13 @@ class SyncThruBinarySensor(CoordinatorEntity, BinarySensorEntity): return self._name @property - def device_info(self): + def device_info(self) -> DeviceInfo | None: """Return device information.""" - return {"identifiers": device_identifiers(self.syncthru)} + if (identifiers := device_identifiers(self.syncthru)) is None: + return None + return DeviceInfo( + identifiers=identifiers, + ) class SyncThruOnlineSensor(SyncThruBinarySensor): diff --git a/homeassistant/components/syncthru/sensor.py b/homeassistant/components/syncthru/sensor.py index cc832f77f0a..a3e24f9ffd8 100644 --- a/homeassistant/components/syncthru/sensor.py +++ b/homeassistant/components/syncthru/sensor.py @@ -1,4 +1,5 @@ """Support for Samsung Printers with SyncThru web interface.""" +from __future__ import annotations import logging @@ -9,6 +10,7 @@ from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.config_entries import SOURCE_IMPORT from homeassistant.const import CONF_NAME, CONF_RESOURCE, CONF_URL, PERCENTAGE import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, DataUpdateCoordinator, @@ -129,9 +131,13 @@ class SyncThruSensor(CoordinatorEntity, SensorEntity): return self._unit_of_measurement @property - def device_info(self): + def device_info(self) -> DeviceInfo | None: """Return device information.""" - return {"identifiers": device_identifiers(self.syncthru)} + if (identifiers := device_identifiers(self.syncthru)) is None: + return None + return DeviceInfo( + identifiers=identifiers, + ) class SyncThruMainSensor(SyncThruSensor): -- GitLab