Skip to content

Commit

Permalink
Use shorthand device info attribute for roomba (#103176)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbede committed Nov 1, 2023
1 parent ae02e3f commit e48cb90
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions homeassistant/components/roomba/irobot_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,23 @@ def __init__(self, roomba, blid):
self.vacuum = roomba
self._blid = blid
self.vacuum_state = roomba_reported_state(roomba)
self._name = self.vacuum_state.get("name")
self._version = self.vacuum_state.get("softwareVer")
self._hw_version = self.vacuum_state.get("hardwareRev")
self._sku = self.vacuum_state.get("sku")

self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self.robot_unique_id)},
serial_number=self.vacuum_state.get("hwPartsRev", {}).get("navSerialNo"),
manufacturer="iRobot",
model=self.vacuum_state.get("sku"),
name=str(self.vacuum_state.get("name")),
sw_version=self.vacuum_state.get("softwareVer"),
hw_version=self.vacuum_state.get("hardwareRev"),
)

if mac_address := self.vacuum_state.get("hwPartsRev", {}).get(
"wlan0HwAddr", self.vacuum_state.get("mac")
):
self._attr_device_info["connections"] = {
(dr.CONNECTION_NETWORK_MAC, mac_address)
}

@property
def robot_unique_id(self):
Expand All @@ -84,25 +97,6 @@ def unique_id(self):
"""Return the uniqueid of the vacuum cleaner."""
return self.robot_unique_id

@property
def device_info(self):
"""Return the device info of the vacuum cleaner."""
connections = None
if mac_address := self.vacuum_state.get("hwPartsRev", {}).get(
"wlan0HwAddr", self.vacuum_state.get("mac")
):
connections = {(dr.CONNECTION_NETWORK_MAC, mac_address)}
return DeviceInfo(
connections=connections,
identifiers={(DOMAIN, self.robot_unique_id)},
serial_number=self.vacuum_state.get("hwPartsRev", {}).get("navSerialNo"),
manufacturer="iRobot",
model=self._sku,
name=str(self._name),
sw_version=self._version,
hw_version=self._hw_version,
)

@property
def battery_level(self):
"""Return the battery level of the vacuum cleaner."""
Expand Down

0 comments on commit e48cb90

Please sign in to comment.