garbage.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from tool.type_ import *
  2. from tool.time_ import HGSTime, hgs_time_t
  3. from tool.location import HGSLocation, hgs_location_t
  4. from enum import Enum
  5. class GarbageBagNotUse(Exception):
  6. pass
  7. class GarbageType(Enum):
  8. recyclable: enum = 1
  9. kitchen: enum = 2
  10. hazardous: enum = 3
  11. other: enum = 4
  12. class GarbageBag:
  13. def __init__(self, gid: gid_t, last_time: time_t):
  14. self._gid: gid_t = gid
  15. self._have_use: bool = False
  16. self.last_time: HGSTime = HGSTime(last_time)
  17. self._type: Union[enum, None] = None
  18. self._use_time: Union[HGSTime, None] = None
  19. self._user: Union[uid_t, None] = None
  20. self._loc: Union[HGSLocation, None] = None
  21. def is_use(self) -> bool:
  22. return self._have_use
  23. def get_user(self) -> uid_t:
  24. if not self._have_use:
  25. raise GarbageBagNotUse
  26. return self._user
  27. def config_use(self, garbage_type: enum, use_time: hgs_time_t, user: uid_t, location: hgs_location_t):
  28. self._have_use = True
  29. if not isinstance(use_time, HGSTime):
  30. use_time = HGSTime(use_time)
  31. if not isinstance(location, HGSLocation):
  32. location = HGSLocation(location)
  33. self._type: enum = garbage_type
  34. self._use_time: HGSTime = use_time
  35. self._user: uid_t = user
  36. self._loc: HGSLocation = location
  37. def is_out_of_date(self) -> bool:
  38. return self.last_time.is_out_of_date()