

One way to make this more Pythonic – and less C or POSIX-oriented – is to use the pathlib library for all filesystem operations. For example, while you could open a file in a contextmanager, pathlib makes it really easy to read a file:
from pathlib import Path
...
config = Path("/some/file/here.conf").read_text()
This automatically opens the file (which checks for existence), reads out the entire file as a string (rather than bytes, but there’s a method for that too), and then closes up the file. If any of those steps go awry, you get a Python exception and a backtrace explaining exactly what happened.


Please explain what you mean by “rotate”. The thermostat is physically turning in-place, as though a wall clock?