Fix multiple components from same fork repo
This commit is contained in:
parent
3c0bc92177
commit
98510843d2
@ -158,11 +158,10 @@ class Unhacs:
|
||||
packages = self.read_lock_packages()
|
||||
|
||||
# Raise an error if the package is already in the list
|
||||
existing_package = next((p for p in packages if p.url == package.url), None)
|
||||
if existing_package:
|
||||
if existing_package := next((p for p in packages if p.same(package)), None):
|
||||
if update:
|
||||
# Remove old version of the package
|
||||
packages = [p for p in packages if p.url != package.url]
|
||||
packages = [p for p in packages if p == existing_package]
|
||||
else:
|
||||
raise ValueError("Package already exists in the list")
|
||||
|
||||
@ -202,8 +201,8 @@ class Unhacs:
|
||||
installed_package.install(self.hass_config)
|
||||
|
||||
# Update lock file to latest now that we know they are uograded
|
||||
latest_lookup = {p.url: p for p in latest_packages}
|
||||
packages = [latest_lookup.get(p.url, p) for p in self.read_lock_packages()]
|
||||
latest_lookup = {p: p for p in latest_packages}
|
||||
packages = [latest_lookup.get(p, p) for p in self.read_lock_packages()]
|
||||
|
||||
self.write_lock_packages(packages)
|
||||
|
||||
|
@ -84,15 +84,25 @@ class Package:
|
||||
return f"{self.package_type}: {name} {version}"
|
||||
|
||||
def __eq__(self, other):
|
||||
return all(
|
||||
(
|
||||
self.same(other),
|
||||
self.fork_component == other.fork_component,
|
||||
)
|
||||
)
|
||||
|
||||
def same(self, other):
|
||||
return all(
|
||||
(
|
||||
self.url == other.url,
|
||||
self.version == other.version,
|
||||
self.branch_name == other.branch_name,
|
||||
self.fork_component == other.fork_component,
|
||||
)
|
||||
)
|
||||
|
||||
def __hash__(self):
|
||||
return hash((self.url, self.branch_name, self.fork_component))
|
||||
|
||||
def verbose_str(self):
|
||||
return f"{str(self)} ({self.url})"
|
||||
|
||||
@ -368,7 +378,7 @@ class Package:
|
||||
def installed_package(self, hass_config_path: Path) -> "Package|None":
|
||||
"""Returns the installed package if it exists, otherwise None."""
|
||||
for package in get_installed_packages(hass_config_path, [self.package_type]):
|
||||
if package.url == self.url:
|
||||
if self.same(package):
|
||||
return package
|
||||
|
||||
return None
|
||||
|
Loading…
Reference in New Issue
Block a user