Example #1
0
def removeDevice(update: Update, context: CallbackContext):
    chat_id = update.message.chat_id

    message = update.message.text
    message = message.lower()
    message = message.replace("rimuovi", "")
    message = message.replace(" ", "")

    try:
        listDevice = retrieveDevicesInfo()
    except Exception:
        context.bot.send_message(chat_id=chat_id, text="Errore nel db")
        return

    for index in range(0, len(listDevice)):
        if listDevice[index].name == message:
            del listDevice[index]
            with open("./db", "w") as file:
                for element in listDevice:
                    file.write(
                        str(JSONSerializer.serialize(element)).replace(
                            "\'", "\"") + "\n")
            context.bot.send_message(chat_id=chat_id, text="Device eliminato")
            return

    context.bot.send_message(chat_id=chat_id, text="Device non trovato")
def putOn(update: Update, context: CallbackContext):
    chat_id = update.message.chat_id

    message = update.message.text
    message = message.lower()
    message = message.replace("accendi", "")
    message = message.replace(" ", "")

    try:
        listDevice = retrieveDevicesInfo()
    except Exception:
        context.bot.send_message(chat_id=chat_id, text="Errore nel db")
        return

    targetDevice = None

    for element in listDevice:
        if element.name == message:
            targetDevice = element

    if targetDevice is None:
        context.bot.send_message(chat_id=chat_id, text="Device non trovato")
        return

    link = createLink(targetDevice, "on")
    requests.get(link, timeout=2)
Example #3
0
    def test_retrieveDevicesInfo_db_with_two_entries(self):
        # Create object to test
        listToTest = retrieveDevicesInfo(path=".\\testsDB\\db_3")

        # Assert
        self.assertEqual(listToTest, [fakeShelly, fakeShelly])
Example #4
0
    def test_retrieveDevicesInfo_empy_db(self):
        # Create object to test
        listToTest = retrieveDevicesInfo(path=".\\testsDB\\db_1")

        # Assert
        self.assertEqual(listToTest, [])