Skip to content

Commit

Permalink
Resolve issue with mixup between BMS and BSP during config
Browse files Browse the repository at this point in the history
  • Loading branch information
ankohanse committed Dec 12, 2024
1 parent 741fb20 commit 22a3b32
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions custom_components/studer_xcom/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,11 @@ async def _async_xcom_devices(self):
self._devices = []
for device in devices:
# In reconfigure, did we already have a deviceConfig for this device?
device_old = next((d for d in self._devices_old if d.address == device.addr), None)
device_old = next((d for d in self._devices_old if StuderDeviceConfig.match(d, device)), None)

self._devices.append(StuderDeviceConfig(
code = device.code,
address = device.addr,
addr = device.addr,
family_id = device.family_id,
family_model = device.family_model,
device_model = device.device_model,
Expand Down
23 changes: 18 additions & 5 deletions custom_components/studer_xcom/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@


class StuderDeviceConfig(XcomDiscoveredDevice):
def __init__(self, code, address, family_id, family_model, device_model, hw_version, sw_version, fid, numbers):
def __init__(self, code, addr, family_id, family_model, device_model, hw_version, sw_version, fid, numbers):
# From XcomDiscoveredDevice
self.code = code
self.address = address
self.addr = addr
self.family_id = family_id
self.family_model = family_model
self.device_model = device_model
Expand All @@ -89,6 +89,19 @@ def __init__(self, code, address, family_id, family_model, device_model, hw_vers
# For StuderDeviceConfig
self.numbers = numbers

@staticmethod
def match(a, b):
if not isinstance(a, XcomDiscoveredDevice) or not isinstance(b, XcomDiscoveredDevice):
return False

# Either match code or match addr and family_id
if a.code == b.code:
return True
if a.addr == b.addr and a.family_id == b.family_id:
return True

return False

@staticmethod
def from_dict(d: dict[str,Any]):
return StuderDeviceConfig(
Expand All @@ -107,7 +120,7 @@ def as_dict(self) -> dict[str, Any]:
"""Return dictionary version of this device config."""
return {
"code": self.code,
"address": self.address,
"address": self.addr,
"family_id": self.family_id,
"family_model": self.family_model,
"device_model": self.device_model,
Expand All @@ -118,7 +131,7 @@ def as_dict(self) -> dict[str, Any]:
}

def __str__(self) -> str:
return f"StuderDeviceConfig(address={self.address}, code={self.code}, family_id={self.family_id}, numbers={self.numbers})"
return f"StuderDeviceConfig(code={self.code}, family_id={self.family_id}, address={self.addr}, numbers={self.numbers})"

def __repr__(self) -> str:
return self.__str__()
Expand Down Expand Up @@ -323,7 +336,7 @@ def _create_entity(self, param: XcomDatapoint, family: XcomDeviceFamily, device:
# Device associated with this entity
device_id = StuderCoordinator.create_id(PREFIX_ID, self._install_id, device.code),
device_code = device.code,
device_addr = device.address,
device_addr = device.addr,
)
return entity

Expand Down
2 changes: 1 addition & 1 deletion custom_components/studer_xcom/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"issue_tracker": "https://github.com/ankohanse/hass-studer-xcom/issues",
"loggers": ["custom_components.studer_xcom"],
"requirements": ["aioxcom>=1.6.1"],
"version": "2024.12.2"
"version": "2024.12.3"
}

0 comments on commit 22a3b32

Please sign in to comment.