From 72603c09efb75a28985dd3bbec907eb2fe3f9093 Mon Sep 17 00:00:00 2001 From: Fredrik Erlandsson Date: Wed, 26 Oct 2022 14:40:49 +0200 Subject: [PATCH] Use the typed dataclass DeviceInfo (#1502) --- docs/device_registry_index.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/device_registry_index.md b/docs/device_registry_index.md index dbba2ecb..38629e63 100644 --- a/docs/device_registry_index.md +++ b/docs/device_registry_index.md @@ -56,18 +56,19 @@ Each entity is able to define a device via the `device_info` property. This prop # Inside a platform class HueLight(LightEntity): @property - def device_info(self): - return { - "identifiers": { + def device_info(self) -> DeviceInfo: + """Return the device info.""" + return DeviceInfo( + identifiers={ # Serial numbers are unique identifiers within a specific domain (hue.DOMAIN, self.unique_id) }, - "name": self.name, - "manufacturer": self.light.manufacturername, - "model": self.light.productname, - "sw_version": self.light.swversion, - "via_device": (hue.DOMAIN, self.api.bridgeid), - } + name=self.name, + manufacturer=self.light.manufacturername, + model=self.light.productname, + sw_version=self.light.swversion, + via_device=(hue.DOMAIN, self.api.bridgeid), + ) ``` Besides device properties, `device_info` can also include `default_manufacturer`, `default_model`, `default_name`. These values will be added to the device registry if no other value is defined just yet. This can be used by integrations that know some information but not very specific. For example, a router that identifies devices based on MAC addresses.