Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shorthand device info attribute for roomba #103176

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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")),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't so great, but its an existing problem so ok for now

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