def toggle_job(self, zone_name, zone_job): with engine.begin() as conn: job_enabled = (self.sa_read_zone_schedule_by_zonejob( zone_name, zone_job)[0][3]) if job_enabled: conn.execute(scheduled_jobs.update().where( and_(scheduled_jobs.c.zone == (zone_name), scheduled_jobs.c.zone_job == (zone_job))).values( {scheduled_jobs.c.job_enabled: False})) else: conn.execute(scheduled_jobs.update().where( and_(scheduled_jobs.c.zone == (zone_name), scheduled_jobs.c.zone_job == (zone_job))).values( {scheduled_jobs.c.job_enabled: True}))
def forced_stopped_jobs(action, job_id): with engine.begin() as conn: if action == 'readall': return (conn.execute(select([scheduled_jobs]).where(scheduled_jobs.c.forced_stop_manually == True))).fetchall() elif action == 'check': return (conn.execute(select([zones_currently_running.c.force_stopped]))).scalar() elif action == 'update': conn.execute(scheduled_jobs.update().where(scheduled_jobs.c.job_id == job_id).values({scheduled_jobs.c.forced_stop_manually: False})) elif action == 'reset': conn.execute(zones_currently_running.update().values({zones_currently_running.c.force_stopped: False}))
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!!.' )
def run_job(self, job_id): with engine.begin() as conn: enabled = (conn.execute( select([hydroponic_zones.c.enabled]).where( hydroponic_zones.c.zone_name == self.zone_name))).scalar() if enabled: with engine.begin() as conn: running = (conn.execute( select([ hydroponic_zones.c.running ]).where(hydroponic_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(hydroponic_zones.update().where( hydroponic_zones.c.zone_name == self.zone_name).values( {hydroponic_zones.c.running: True})) conn.execute(hydroponic_zones.update().where( hydroponic_zones.c.zone_name == self.zone_name).values( {hydroponic_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.' )
def update_job_duration(self, zone_name, zone_job, job_duration): with engine.begin() as conn: conn.execute(scheduled_jobs.update().where( and_(scheduled_jobs.c.zone == (zone_name), scheduled_jobs.c.zone_job == (zone_job))).values( {scheduled_jobs.c.job_duration: job_duration}))
def update_job_start_time(self, zone_name, zone_job, job_start_time): with engine.begin() as conn: conn.execute(scheduled_jobs.update().where( and_(scheduled_jobs.c.zone == (zone_name), scheduled_jobs.c.zone_job == (zone_job))).values( {scheduled_jobs.c.job_start_time: job_start_time}))
def update_day(self, zone_name, zone_job, day_of_week, value): with engine.begin() as conn: conn.execute(scheduled_jobs.update().where( and_(scheduled_jobs.c.zone == (zone_name), scheduled_jobs.c.zone_job == (zone_job))).values( {getattr(scheduled_jobs.c, day_of_week): value}))