示例#1
0
 def run_job(self, job_id):
     with engine.begin() as conn:
         enabled = (conn.execute(
             select([
                 zones.c.enabled
             ]).where(zones.c.zone_name == self.zone_name))).scalar()
     if enabled:
         with engine.begin() as conn:
             running = (conn.execute(
                 select([
                     zones.c.running
                 ]).where(zones.c.zone_name == self.zone_name))).scalar()
         if running:
             log.debug(
                 f'Zone {self.zone_number} ({self.zone_name}) is already running.'
             )
         else:
             self.running = True
             with engine.begin() as conn:
                 # With this db update we are updating the individual zone db record for the zone that is running.
                 conn.execute(zones.update().where(
                     zones.c.zone_name == self.zone_name).values(
                         {zones.c.running: True}))
                 conn.execute(zones.update().where(
                     zones.c.zone_name == self.zone_name).values(
                         {zones.c.running_manually: False}))
                 conn.execute(scheduled_jobs.update().where(
                     scheduled_jobs.c.job_id == job_id).values(
                         {scheduled_jobs.c.job_running: True}))
                 # With this db update we are updating the system_wide indication that "a" or "any" zone is running.
                 # To access this, call use_database.zones_running_now() and it will return True or False on a systemwide
                 # basis.
                 conn.execute(zones_currently_running.update().values(
                     {zones_currently_running.c.currently_running: True}))
                 conn.execute(zones_currently_running.update().values(
                     {zones_currently_running.c.run_manually: False}))
                 conn.execute(zones_currently_running.update().values(
                     {zones_currently_running.c.run_by_job: True}))
                 conn.execute(zones_currently_running.update().values(
                     {zones_currently_running.c.job_id: job_id}))
                 mcp.pinMode(self.gpio, 1)
                 mcp.digitalWrite(self.gpio, 1)
             log.debug(
                 f'Zone {self.zone_number} ({self.zone_name}) is now RUNNING.'
             )
     else:
         log.debug(
             f'ERROR: Zone {self.zone_number} ({self.zone_name}) is DISABLED. Please enable it first.'
         )
示例#2
0
 def disable(self):
     with engine.begin() as conn:
         enabled = (conn.execute(
             select([
                 zones.c.enabled
             ]).where(zones.c.zone_name == self.zone_name))).scalar()
     if enabled:
         with engine.begin() as conn:
             running = (conn.execute(
                 select([
                     zones.c.running
                 ]).where(zones.c.zone_name == self.zone_name))).scalar()
         if running:
             log.debug(
                 f'Zone {self.zone_number} ({self.zone_name}) is currently running.'
             )
             log.debug(
                 f'Shutting off Zone {self.zone_number} ({self.zone_name}) before disabling.'
             )
             self.stop()
         self.enabled = False
         with engine.begin() as conn:
             conn.execute(zones.update().where(
                 zones.c.zone_name == self.zone_name).values(
                     {zones.c.enabled: False}))
         log.debug(
             f'Zone {self.zone_number} ({self.zone_name}) has been disbled.'
         )
     else:
         log.debug(
             f'Zone {self.zone_number} ({self.zone_name}) is already disabled.'
         )
示例#3
0
 def notification_toggle(self, notification):
     with engine.begin() as conn:
         if getattr(self, notification):
             conn.execute(zones.update().where(
                 zones.c.zone_name == self.zone_name).values(
                     {notification: False}))
             setattr(self, notification, False)
             log.debug(
                 f'System Notifications: ({notification}) for Zone {self.zone_number} ({self.zone_name}) Disabled.'
             )
         else:
             conn.execute(zones.update().where(
                 zones.c.zone_name == self.zone_name).values(
                     {notification: True}))
             setattr(self, notification, True)
             log.debug(
                 f'System Notifications: ({notification}) for Zone {self.zone_number} ({self.zone_name}) Enabled.'
             )
示例#4
0
 def stop_job(self, job_id, forced):
     with engine.begin() as conn:
         running = (conn.execute(
             select([
                 zones.c.running
             ]).where(zones.c.zone_name == self.zone_name))).scalar()
     if running:
         self.running = False
         with engine.begin() as conn:
             # With this db update we are updating the individual zone db record for the zone that is running.
             conn.execute(zones.update().where(
                 zones.c.zone_name == self.zone_name).values(
                     {zones.c.running: False}))
             conn.execute(zones.update().where(
                 zones.c.zone_name == self.zone_name).values(
                     {zones.c.running_manually: False}))
             conn.execute(scheduled_jobs.update().where(
                 scheduled_jobs.c.job_id == job_id).values(
                     {scheduled_jobs.c.job_running: False}))
             if forced:
                 conn.execute(scheduled_jobs.update().where(
                     scheduled_jobs.c.job_id == job_id).values(
                         {scheduled_jobs.c.forced_stop_manually: True}))
                 conn.execute(zones_currently_running.update().values(
                     {zones_currently_running.c.force_stopped: True}))
             # With this db update we are updating the system_wide indication that "a" or "any" zone is running.
             # To access this, call use_database.zones_running_now() and it will return True or False on a systemwide
             # basis.
             conn.execute(zones_currently_running.update().values(
                 {zones_currently_running.c.currently_running: False}))
             conn.execute(zones_currently_running.update().values(
                 {zones_currently_running.c.run_manually: False}))
             conn.execute(zones_currently_running.update().values(
                 {zones_currently_running.c.run_by_job: False}))
             conn.execute(zones_currently_running.update().values(
                 {zones_currently_running.c.job_id: 0}))
             mcp.digitalWrite(self.gpio, 0)
         log.debug(
             f'Zone {self.zone_number} ({self.zone_name}) is now STOPPED.')
     else:
         log.debug(
             f'Zone {self.zone_number} ({self.zone_name}) is not currently running!!.'
         )
示例#5
0
def water_usage(zone_name, action, value):
    with engine.begin() as conn:
        if action == 'update_gallons_stop':
            conn.execute(
                zones.update().where(zones.c.zone_name == zone_name).values(
                    {zones.c.gallons_stop: value}))
        elif action == 'read_gallons_stop':
            return (conn.execute(
                select([zones.c.gallons_stop
                        ]).where(zones.c.zone_name == (zone_name)))).scalar()
        elif action == 'read_gallons_start':
            return (conn.execute(
                select([zones.c.gallons_start
                        ]).where(zones.c.zone_name == (zone_name)))).scalar()
        elif action == 'read_total_gallons_used':
            return (conn.execute(
                select([zones.c.total_gallons_used
                        ]).where(zones.c.zone_name == (zone_name)))).scalar()
        elif action == 'read_gallons_last_run':
            return (conn.execute(
                select([zones.c.gallons_last_run
                        ]).where(zones.c.zone_name == (zone_name)))).scalar()
        elif action == 'read_gallons_current_run':
            return (conn.execute(
                select([zones.c.gallons_current_run
                        ]).where(zones.c.zone_name == (zone_name)))).scalar()
        elif action == 'update_gallons_start':
            conn.execute(
                zones.update().where(zones.c.zone_name == zone_name).values(
                    {zones.c.gallons_start: value}))
        elif action == 'update_gallons_current_run':
            conn.execute(
                zones.update().where(zones.c.zone_name == zone_name).values(
                    {zones.c.gallons_current_run: value}))
        elif action == 'update_gallons_last_run':
            conn.execute(
                zones.update().where(zones.c.zone_name == zone_name).values(
                    {zones.c.gallons_last_run: value}))
        elif action == 'update_total_gallons_used':
            conn.execute(
                zones.update().where(zones.c.zone_name == zone_name).values(
                    {zones.c.total_gallons_used: value}))
示例#6
0
 def enable(self):
     with engine.begin() as conn:
         enabled = (conn.execute(
             select([
                 zones.c.enabled
             ]).where(zones.c.zone_name == self.zone_name))).scalar()
     if enabled:
         log.debug(
             f'Zone {self.zone_number} ({self.zone_name}) is already enabled.'
         )
     else:
         self.enabled = True
         with engine.begin() as conn:
             conn.execute(zones.update().where(
                 zones.c.zone_name == self.zone_name).values(
                     {zones.c.enabled: True}))
         log.debug(
             f'Zone {self.zone_number} ({self.zone_name}) has been enabled.'
         )
示例#7
0
def zone_enable(zone_name):
    with engine.begin() as conn:
        conn.execute(zones.update().where(zones.c.zone_name == zone_name).values({zones.c.enabled: True}))