diff --git a/src/check_phat_nguoi/config/models/plate_info.py b/src/check_phat_nguoi/config/models/plate_info.py index eef94ee..632cc01 100644 --- a/src/check_phat_nguoi/config/models/plate_info.py +++ b/src/check_phat_nguoi/config/models/plate_info.py @@ -7,6 +7,7 @@ from check_phat_nguoi.types import ( ApiEnum, VehicleType, + get_vehicle_enum, ) @@ -43,13 +44,37 @@ class PlateInfo(BaseModel): ) @override - def __hash__(self): - return hash(self.plate) + def __hash__(self) -> int: + return ( + hash(self.plate) + + hash(self.type) + + hash(self.enabled) + + hash(self.api) + + hash(self.owner) + ) @override def __eq__(self, other: Any): if isinstance(other, PlateInfo): - return self.plate == other.plate + return ( + self.plate == other.plate + and get_vehicle_enum(self.type) == get_vehicle_enum(other.type) + and self.enabled == other.enabled + and self.owner == other.owner + and ( + all( + x == y + for x, y in zip( + (self.api,) if isinstance(self.api, ApiEnum) else self.api, + (other.api,) + if isinstance(other.api, ApiEnum) + else other.api, + ) + ) + if self.api and other.api + else (not self.api and not other.api) + ) + ) return False diff --git a/src/check_phat_nguoi/context/plates/models/plate_detail.py b/src/check_phat_nguoi/context/plates/models/plate_detail.py index ff03bd8..4148d51 100644 --- a/src/check_phat_nguoi/context/plates/models/plate_detail.py +++ b/src/check_phat_nguoi/context/plates/models/plate_detail.py @@ -4,7 +4,7 @@ from pydantic import BaseModel, Field -from check_phat_nguoi.types import VehicleTypeEnum +from check_phat_nguoi.types import VehicleTypeEnum, get_vehicle_enum from .violation_detail import ViolationDetail @@ -19,12 +19,26 @@ class PlateDetail(BaseModel): @override def __hash__(self): - return hash(self.plate) + return ( + hash(self.plate) + + hash(self.owner) + + hash(self.type) + + hash(self.violations) + ) @override def __eq__(self, other: Any): if isinstance(other, PlateDetail): - return self.plate == other.plate + return ( + self.plate == other.plate + and self.owner == other.owner + and get_vehicle_enum(self.type) == get_vehicle_enum(other.type) + and ( + all(x == y for x, y in zip(self.violations, other.violations)) + if self.violations and other.violations + else (not self.violations and not other.violations) + ) + ) return False def __str__(self): diff --git a/src/check_phat_nguoi/context/plates/models/violation_detail.py b/src/check_phat_nguoi/context/plates/models/violation_detail.py index 7d666bd..572b84c 100644 --- a/src/check_phat_nguoi/context/plates/models/violation_detail.py +++ b/src/check_phat_nguoi/context/plates/models/violation_detail.py @@ -39,4 +39,4 @@ class ViolationDetail(BaseModel): @override def __hash__(self): - return hash(f"{self.date}{self.location}") + return hash(self.date) + hash(self.location)