Commit 5bf5389b authored by Nikita Yurishev's avatar Nikita Yurishev

deleted wrote to log file logic

parent c7499761
......@@ -18,8 +18,6 @@ l = log.getLogger('zytemp')
_CO2MON_MAGIC_WORD = b'Htemp99e'
_CO2MON_MAGIC_TABLE = (0, 0, 0, 0, 0, 0, 0, 0)
LOG_FILE = 'co2data.log'
def list_to_longint(x):
return sum([val << (i * 8) for i, val in enumerate(x[::-1])])
......@@ -60,22 +58,10 @@ class ZyTemp():
def update(self, key, value, values):
values[key] = value
# Проверяем, если обе переменные имеют значения
if all(value is not None for value in values.values()):
# Запись значений в лог-файл с меткой времени
try:
with open(LOG_FILE, 'a') as f:
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
f.write(f"{timestamp} - {values}\n")
l.debug(f"Successfully wrote data to {LOG_FILE}")
except Exception as e:
l.error(f"Failed to write data to {LOG_FILE}: {e}")
print(values)
# Выход после записи в лог
sys.exit(0)
#Функция получения данных с детектора
def run_once(self, decrypt=False):
while True:
try:
......@@ -101,7 +87,6 @@ class ZyTemp():
continue
if r[3] != sum(r[0:3]) & 0xff:
# l.error(f'Checksum error')
continue
m_type = r[0]
......@@ -149,14 +134,8 @@ def get_hiddev():
return h
if __name__ == "__main__":
log.basicConfig(level=log.DEBUG)
# Проверка на наличие файла co2data.log, создание при отсутствии
if not os.path.exists(LOG_FILE):
with open(LOG_FILE, 'w') as f:
f.write("CO2 and Temperature data log\n")
hiddev = get_hiddev()
if hiddev is None:
sys.exit(1)
......@@ -164,8 +143,5 @@ if __name__ == "__main__":
zytemp = ZyTemp(hiddev)
zytemp.run_once()
# Вывод значений переменных temperature и co2 в консоль
temperature = zytemp.values.get('Temperature', 'N/A')
co2 = zytemp.values.get('CO2', 'N/A')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment