def checkAndLog(self):
     if self.lastEnergy is not None and self.lastPower is not None:
         try:
             dbConnection = DbConnection()
             if self.isFirstMeasurment or self.lastLoggedEnergy > self.lastEnergy:
                 self.dbIdSeries = dbConnection.createNewSeries(
                     self.dbIdTestDevice)
                 self.logger.info(
                     "Create New Series dbId %s after Shelly Reboot" %
                     self.dbIdSeries)
             self.isFirstMeasurment = False
             self.lastLoggedEnergy = self.lastEnergy
             dbConnection.createMeasurement(self.dbIdSeries, self.lastPower,
                                            self.lastEnergy, 1)
             dbConnection.close()
         except Exception as e:
             self.logger.warning(e)
         self.lastPower = None
         self.lastEnergy = None
from DbConnection import DbConnection
from mySwitch import MySwitch

DEVICE_NAME = "3E0B80"
DEVICE_IP = "192.168.1.52"

current_milli_time = lambda: int(round(time.time() * 1000))

if __name__ == "__main__":
    dbConnection = DbConnection()

    dbIdTestDevice = dbConnection.findDataloggerDbIdByName(DEVICE_NAME)

    print("Device dbId", dbIdTestDevice)

    dbIdSeries = dbConnection.createNewSeries(dbIdTestDevice)

    print("Series dbId", dbIdSeries)

    dbConnection.createMeasurement(dbIdSeries, 1, 2, 1)

    switch = MySwitch(DEVICE_IP)

    energy = 0
    t = current_milli_time()

    while (True):
        values = switch.getReport()
        dT = current_milli_time() - t
        t = current_milli_time()
        power = values["power"]