Added more code

This commit is contained in:
2026-02-26 17:09:56 +01:00
parent be895664d1
commit fe51d046f6
3 changed files with 132 additions and 41 deletions

View File

@@ -4,6 +4,7 @@ from datetime import datetime, timezone, timedelta
from typing import Optional, Annotated
from sqlalchemy.dialects.mysql import MEDIUMINT, TINYINT, TEXT, TIMESTAMP, FLOAT
from sqlalchemy.ext.declarative import declarative_base
from dataclasses import dataclass
# -----------
@@ -41,21 +42,23 @@ class snmpValueToHost():
lastV: Annotated[str, "Last value\nNone when initializing"] = None,
remote: Annotated[str, "Needs to be a valid IP address"] = None,
nextV: Annotated[str, "Value to insert next\nNone when initializing"] = None,
lasttime: Annotated[float, "Last time since sending data\nSince Epoch"] = time.time(),
lasttime: Annotated[float, "Last time since sending data\nSince Epoch, so time.time()"] = None,
lastStatus: Annotated[bool, "True if value newest value was inserted\nFalse if data is pending to be sent"] = False
):
self.__lastValue = lastV # Save last sent value
self.__remote = remote # Remote IP address of the SNMP client
self.__nextValue = nextV # Next value to send. Maybe will be used
self.__lastSentStatus = lastStatus # If previously sent new data, set to True.
self.__lastSentTime = lasttime # The time since the Epoch of the last sent data*
self.__lastSentTime = lasttime if lasttime else time.time() # The time since the Epoch of the last sent data*
def ___str__():
def ___str__(self):
return self.__lastValue
def __changeLastSentValue(slef):
def __changeLastSentValue(self, newValue: int) -> bool:
self.__nextValue == newValue
self.__lastValue = self.__nextValue
self.__nextValue == None
return True
def __updateLastSentTime(self):
@@ -71,5 +74,23 @@ class snmpValueToHost():
return True
def updateStats(self, nextV: Annotated[int, "Value that will be set as the new one"]):
...
__changeLastSentValue(nextV)
__updateLastSentTime()
...
# Dataclasses--------------------------------------------
@dataclass
class snmpPyData():
"""Dataclass for snmp data"""
hostname: str
powerDrawPSU1: int
powerDrawPSU2: int
voltagePSU1: int
voltagePSU2: int
inletTemp: float
exhaustTemp: float
uptime: int