Skip to content

Instantly share code, notes, and snippets.

@ozkansen
Created July 26, 2021 08:16
Show Gist options
  • Save ozkansen/c97784c56b0e695e04cf5739fc425f73 to your computer and use it in GitHub Desktop.
Save ozkansen/c97784c56b0e695e04cf5739fc425f73 to your computer and use it in GitHub Desktop.
import datetime
from dataclasses import dataclass
@dataclass
class ArduinoStatus:
sicaklik : float
battery : float
isik_sens : int
isik_role : int
kasa_kapak : int
cpu_fan : int
sc_relay : int
buzzer : int
busy : int
elevator : int
ups_on : int
nets_on : int
on_charge : int
standby : int
state : int
battery_error: int
zaman : datetime.time
tarih : datetime.datetime
ups_kapat : int
raw = "<sicaklik=-47.99&battery=43.36&isik_sens=0&isik_role=0&kasa_kapak=0&cpu_fan=1&sc_relay=0&buzzer=0&busy=0&elevator=0&ups_on=1,nets_on=1&on_charge=0&standby=1&state=2&battery_error=0&zaman=14:26:46&tarih=01.02.2021&ups_kapat=0>"
raw = raw.replace("<", "")
raw = raw.replace(">", "")
raw_status = {}
for r in raw.split("&"):
if r.startswith("sicaklik="):
raw_status["sicaklik"] =r[9:]
print(raw_status)
@YusufEminDemirci
Copy link

import datetime
from dataclasses import dataclass

@dataclass
class ArduinoStatus:
    sicaklik : float
    battery : float
    isik_sens : int
    isik_role : int
    kasa_kapak : int
    cpu_fan : int
    sc_relay : int
    buzzer : int
    busy : int
    elevator : int
    ups_on : int
    nets_on : int
    on_charge : int
    standby : int
    state : int
    battery_error: int
    zaman : datetime.time
    tarih : datetime.datetime
    ups_kapat : int


raw = "<sicaklik=-47.99&battery=43.36&isik_sens=0&isik_role=0&kasa_kapak=0&cpu_fan=1&sc_relay=0&buzzer=0&busy=0&elevator=0&ups_on=1,nets_on=1&on_charge=0&standby=1&state=2&battery_error=0&zaman=14:26:46&tarih=01.02.2021&ups_kapat=0>"
raw = raw.replace("<", "")
raw = raw.replace(">", "")

raw_status = {}
for r in raw.split("&"):
    if r.startswith("sicaklik="):
        raw_status["sicaklik"] = r[9:]
    if r.startswith("battery="):
        raw_status["battery"] = r[8:]
    if r.startswith("isik_sens="):
        raw_status["isik_sens"] = r[10:]
    if r.startswith("isik_role="):
        raw_status["isik_role"] = r[10:]
    if r.startswith("kasa_kapak="):
        raw_status["kasa_kapak"] = r[11:]
    if r.startswith("cpu_fan="):
        raw_status["cpu_fan"] = r[8:]
    if r.startswith("sc_relay="):
        raw_status["sc_relay"] = r[9:]
    if r.startswith("buzzer="):
        raw_status["buzzer"] = r[7:]
    if r.startswith("busy="):
        raw_status["busy"] = r[5:]
    if r.startswith("elevator="):
        raw_status["elevator"] = r[9:]
    if r.startswith("ups_on="):
        for x in r.split(","):
            if x.startswith("ups_on="):
                raw_status["ups_on"] = x[7:]
            if x.startswith("nets_on="):
                raw_status["nets_on"] = x[8:]
    if r.startswith("on_charge="):
        raw_status["on_charge"] = r[10:]
    if r.startswith("standby="):
        raw_status["standby"] = r[8:]
    if r.startswith("state="):
        raw_status["state"] = r[6:]
    if r.startswith("battery_error="):
        raw_status["battery_error"] = r[14:]
    if r.startswith("zaman="):
        raw_status["zaman"] = r[6:]
    if r.startswith("tarih="):
        raw_status["tarih"] = r[6:]
    if r.startswith("ups_kapat="):
        raw_status["ups_kapat"] = r[10:]



print(raw_status)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment