@@ -262,41 +262,35 @@ def data(self) -> dict[str, Any]:
262262
263263 def __eq__ (self , other : Any ) -> bool :
264264 """Return true if backups have same metadata."""
265- if not isinstance (other , Backup ):
266- return False
265+ return isinstance (other , Backup ) and self .slug == other .slug
267266
268- # Compare all fields except ones about protection. Current encryption status does not affect equality
269- keys = self ._data .keys () | other ._data .keys ()
270- for k in keys - IGNORED_COMPARISON_FIELDS :
271- if (
272- k not in self ._data
273- or k not in other ._data
274- or self ._data [k ] != other ._data [k ]
275- ):
276- _LOGGER .info (
277- "Backup %s and %s not equal because %s field has different value: %s and %s" ,
278- self .slug ,
279- other .slug ,
280- k ,
281- self ._data .get (k ),
282- other ._data .get (k ),
283- )
284- return False
285- return True
267+ def __hash__ (self ) -> int :
268+ """Return hash of backup."""
269+ return hash (self .slug )
286270
287271 def consolidate (self , backup : Self ) -> None :
288272 """Consolidate two backups with same slug in different locations."""
289- if self . slug != backup . slug :
273+ if self != backup :
290274 raise ValueError (
291275 f"Backup { self .slug } and { backup .slug } are not the same backup"
292276 )
293- if self != backup :
294- raise BackupInvalidError (
295- f"Backup in { backup .location } and { self .location } both have slug { self .slug } but are not the same!"
296- )
297277
298- # In case of conflict we always ignore the ones from the first one. But log them to let the user know
278+ # Compare all fields except ones about protection. Current encryption status does not affect equality
279+ other_data = backup ._data # pylint: disable=protected-access
280+ keys = self ._data .keys () | other_data .keys ()
281+ for k in keys - IGNORED_COMPARISON_FIELDS :
282+ if (
283+ k not in self ._data
284+ or k not in other_data
285+ or self ._data [k ] != other_data [k ]
286+ ):
287+ raise BackupInvalidError (
288+ f"Cannot consolidate backups in { backup .location } and { self .location } with slug { self .slug } "
289+ f"because field { k } has different values: { self ._data .get (k )} and { other_data .get (k )} !" ,
290+ _LOGGER .error ,
291+ )
299292
293+ # In case of conflict we always ignore the ones from the first one. But log them to let the user know
300294 if conflict := {
301295 loc : val .path
302296 for loc , val in self .all_locations .items ()
0 commit comments