Example #1
0
def read_meter(device, dest_file, usb, erase=False):
    plg = Plug(device, usb)
    last_ts = 0
    #open the destination file and read the last timestamp
    if (os.path.isfile(dest_file)):
        with open(dest_file) as f:
            reader = csv.reader(f)
            for row in reader:
                last_ts = row[0]
    #check the plug for new data
    data = plg.get_data(int(float(last_ts)))
    if (data == None):
        print("no new data available, exiting")
    else:
        #if we are on wifi, append the data to the file
        if (usb == False):
            with open(dest_file, 'a') as f:
                writer = csv.writer(f)
                writer.writerows(data)
        #if this is a USB data dump, don't append
        else:
            with open(dest_file, 'w') as f:
                writer = csv.writer(f)
                writer.writerows(data)
            #erase if requested
            if (erase):
                plg.erase_data()
                print "\t erased data"
            print "All data retrieved, unplug smartee to reset"
Example #2
0
    async def run(self, loop):
        _logger.info("----- CONNECTING TO FHEM -----")
        fhem_connection = self.connect_fhem()

        _logger.info("----- CONNECTING TO MEROSS -----")
        self._meross = await self.connect_meross()

        _logger.info("----- INITIALIZING DEVICES -----")
        devices = self._meross.find_devices()
        for dev in devices:
            if dev.type == "msg100":
                await self.init_device(
                    GarageDoorOpener(dev, fhem_connection, _logger))
            if dev.type == "mss310":
                await self.init_device(Plug(dev, fhem_connection, _logger))

        _logger.info("----- START LISTEN TO FHEM -----")
        que = Queue()
        t = threading.Thread(target=self.start_listen_to_fhem,
                             args=(que, loop))
        t.daemon = True
        t.start()

        _logger.info("----- INITIALIZATION FINISHED -----")

        await self.__shutdown_event.wait()

        _logger.info("----- SHUTDOWN COMPLETE -----")
 def addPlug(self, testName):
     p = Plug(testName)
     self.measurements.append(p)
     return p
Example #4
0
def set_relay(device, value, usb):
    plg = Plug(device, usb)
    plg.set_relay(value)