Ejemplo n.º 1
0
 def find_hive(name: str) -> []:
     conn = DbAccess._db_connect()
     c = conn.cursor()
     c.execute(
         "SELECT id, bezeichnung, kalib_val_pro_gramm FROM beehive where bezeichnung=?",
         [name])
     row = c.fetchone()
     hive = Hive(row[0], row[1])
     hive.set_calibrated(row[2] is not None)
     DbAccess._append_sensors(hive)
     DbAccess._commit_and_close(conn)
     return hive
Ejemplo n.º 2
0
 def find_hives() -> []:
     hives = []
     conn = DbAccess._db_connect()
     c = conn.cursor()
     for row in c.execute(
             "SELECT id, bezeichnung, kalib_val_pro_gramm FROM beehive"):
         print(row[0])
         print(row[1])
         hive = Hive(row[0], row[1])
         hive.set_calibrated(row[2] is not None)
         DbAccess._append_sensors(hive)
         hives.append(hive)
     DbAccess._commit_and_close(conn)
     return hives
Ejemplo n.º 3
0
    def update_hive(hive: Hive):
        conn = DbAccess._db_connect()
        c = conn.cursor()
        c.execute('''update beehive set bezeichnung=? where id=?''',
                  [hive.get_name(), hive.get_id()])
        c.execute('''delete from sensor where idbeehive=?''', [hive.get_id()])
        sensors = [[TEMP_IN, hive.get_temperature_inside()],
                   [TEMP_OUT, hive.get_temperature_outside()],
                   [HUMIDITY_IN, hive.get_humidity_inside()],
                   [HUMIDITY_OUT, hive.get_humidity_outside()],
                   [WEIGHT, hive.get_weight()]]
        for sensor in sensors:
            if sensor[1] is not None:
                c.execute(
                    '''INSERT into sensor (idbeehive, typ, gpio, product) values (?, ?, ?, ?)''',
                    [
                        hive.get_id(), sensor[0], sensor[1].get_bcm().strip(),
                        sensor[1].get_product().strip()
                    ])

        DbAccess._commit_and_close(conn)
Ejemplo n.º 4
0
 def delete_hive(hive: Hive):
     conn = DbAccess._db_connect()
     c = conn.cursor()
     c.execute('''delete from sensor where idbeehive=?''', [hive.get_id()])
     c.execute('''delete from  beehive where id=?''', [hive.get_id()])
     DbAccess._commit_and_close(conn)
Ejemplo n.º 5
0
 def _append_sensors(hive: Hive):
     conn = DbAccess._db_connect()
     c = conn.cursor()
     print('hive.id: ', hive.get_id())
     for row in c.execute(
             "SELECT gpio, typ, product FROM sensor where idbeehive=?",
         [hive.get_id()]):
         print(row)
         sensor = Sensor()
         sensor.set_bcm(row[0])
         sensor.set_product(row[2])
         if row[1] == TEMP_IN:
             hive.set_temperature_inside(sensor)
         elif row[1] == TEMP_OUT:
             hive.set_temperature_outside(sensor)
         elif row[1] == HUMIDITY_IN:
             hive.set_humidity_inside(sensor)
         elif row[1] == HUMIDITY_OUT:
             hive.set_humidity_outside(sensor)
         elif row[1] == WEIGHT:
             hive.set_weight(sensor)
     DbAccess._commit_and_close(conn)
Ejemplo n.º 6
0
    def _add_to_frame(self, hive: Hive):
        i = len(self._frame.winfo_children()) + 1

        name_txt = StringVar(value=hive.get_name())
        temp_in_txt = StringVar(value=hive.get_temperature_inside().get_bcm())
        temp_in_prd_txt = StringVar(
            value=hive.get_temperature_inside().get_product())
        temp_out_txt = StringVar(
            value=hive.get_temperature_outside().get_bcm())
        temp_out_prd_txt = StringVar(
            value=hive.get_temperature_outside().get_product())
        hum_in_txt = StringVar(value=hive.get_humidity_inside().get_bcm())
        hum_in_prd_txt = StringVar(
            value=hive.get_humidity_inside().get_product())
        hum_out_txt = StringVar(value=hive.get_humidity_outside().get_bcm())
        hum_out_prd_txt = StringVar(
            value=hive.get_humidity_outside().get_product())
        weight_txt = StringVar(value=hive.get_weight().get_bcm())
        weight_prd_txt = StringVar(value=hive.get_weight().get_product())

        row_buttons_container = tk.Frame(self._frame, background='#ffffcc')
        row_buttons_container.grid(row=i, column=6, padx=5)

        delete_button = Button(row_buttons_container,
                               text="Löschen",
                               background="#ccffff",
                               width="15",
                               command=lambda: self._delete_hive(
                                   hive, row_buttons_container, widgets))
        calibrate_button = Button(
            row_buttons_container,
            text="Waage kalibrierren",
            background="#ccffff",
            width="15",
            command=lambda: self._open_calibration_dialog(hive))

        update_button = Button(self._frame,
                               text="Speichern",
                               background="#ccffff",
                               width="15",
                               command=lambda: self._update_hive(
                                   hive,
                                   name_txt.get().strip(),
                                   temp_in_txt.get().strip(),
                                   temp_in_prd_txt.get().strip(),
                                   temp_out_txt.get().strip(),
                                   temp_out_prd_txt.get().strip(),
                                   hum_in_txt.get().strip(),
                                   hum_in_prd_txt.get().strip(),
                                   hum_out_txt.get().strip(),
                                   hum_out_prd_txt.get().strip(),
                                   weight_txt.get().strip(),
                                   weight_prd_txt.get().strip(), update_button,
                                   delete_button, calibrate_button, i))
        change_function = lambda a: self._hive_val_changed(
            hive, update_button, delete_button, i)

        widgets = [
            self._create_bcm_entry(i, 0, name_txt, self._frame,
                                   entry_width=30),
            self._create_bcm_entry(i,
                                   1,
                                   temp_in_txt,
                                   self._frame,
                                   product_values=SUPPORTED_TEMP_PRODS,
                                   product_txt=temp_in_prd_txt,
                                   change_function=change_function),
            self._create_bcm_entry(i,
                                   2,
                                   temp_out_txt,
                                   self._frame,
                                   product_values=SUPPORTED_TEMP_PRODS,
                                   product_txt=temp_out_prd_txt,
                                   change_function=change_function),
            self._create_bcm_entry(i,
                                   3,
                                   hum_in_txt,
                                   self._frame,
                                   product_values=SUPPORTED_HUMID_PRODS,
                                   product_txt=hum_in_prd_txt,
                                   change_function=change_function),
            self._create_bcm_entry(i,
                                   4,
                                   hum_out_txt,
                                   self._frame,
                                   product_values=SUPPORTED_HUMID_PRODS,
                                   product_txt=hum_out_prd_txt,
                                   change_function=change_function),
            self._create_bcm_entry(i,
                                   5,
                                   weight_txt,
                                   self._frame,
                                   product_values=SUPPORTED_WEIGHT_PRODS,
                                   product_txt=weight_prd_txt,
                                   change_function=change_function)
        ]

        widgets.append(update_button)

        name_txt.trace(
            'w', lambda a, b, c: self._hive_val_changed(
                hive, update_button, delete_button, i))
        temp_in_txt.trace(
            'w', lambda a, b, c: self._hive_val_changed(
                hive, update_button, delete_button, i))
        temp_out_txt.trace(
            'w', lambda a, b, c: self._hive_val_changed(
                hive, update_button, delete_button, i))
        hum_in_txt.trace(
            'w', lambda a, b, c: self._hive_val_changed(
                hive, update_button, delete_button, i))
        hum_out_txt.trace(
            'w', lambda a, b, c: self._hive_val_changed(
                hive, update_button, delete_button, i))
        weight_txt.trace(
            'w', lambda a, b, c: self._hive_val_changed(
                hive, update_button, delete_button, i))

        delete_button.grid(row=0, column=0, padx=5)
        calibrate_button.grid(row=1, column=0, padx=5, pady=2)
Ejemplo n.º 7
0
 def _update_hive(self, hive: Hive, name: str, temp_in, temp_in_prod,
                  temp_out, temp_out_prod, hum_in, hum_in_prod, hum_out,
                  hum_out_prod, weight, weight_prod, update_button: Button,
                  delete_button: Button, calibrate_button: Button, row_num):
     hive.set_name(name)
     hive.get_temperature_inside().set_bcm(temp_in)
     hive.get_temperature_inside().set_product(temp_in_prod)
     hive.get_temperature_outside().set_bcm(temp_out)
     hive.get_temperature_outside().set_product(temp_out_prod)
     hive.get_humidity_inside().set_bcm(hum_in)
     hive.get_humidity_inside().set_product(hum_in_prod)
     hive.get_humidity_outside().set_bcm(hum_out)
     hive.get_humidity_outside().set_product(hum_out_prod)
     hive.get_weight().set_bcm(weight)
     hive.get_weight().set_product(weight_prod)
     DbAccess.update_hive(hive)
     update_button.grid_remove()
     #delete_button.grid(row=row_num, column=6)
     #calibrate_button.grid(row=row_num, column=6)
     delete_button.grid(row=0, column=0, padx=5)
     calibrate_button.grid(row=1, column=0, padx=5, pady=2)