time.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright 2024 Google LLC
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from .. import PebbleCommander, exceptions, parsers
  15. @PebbleCommander.command()
  16. def set_time(cmdr, new_time):
  17. """ Set the time.
  18. `new_time` should be in epoch seconds.
  19. """
  20. new_time = int(str(new_time), 0)
  21. if new_time < 1262304000:
  22. raise exceptions.ParameterError("time must be later than 2010-01-01")
  23. ret = cmdr.send_prompt_command("set time %s" % new_time)
  24. if not ret[0].startswith("Time is now"):
  25. raise exceptions.PromptResponseError(ret)
  26. return ret
  27. @PebbleCommander.command()
  28. def timezone_clear(cmdr):
  29. """ Clear timezone settings.
  30. """
  31. ret = cmdr.send_prompt_command("timezone clear")
  32. if ret:
  33. raise exceptions.PromptResponseError(ret)