Sha256: a771325ccca28bea97c28bb892405ced3bce2e77b3a06c352873933ec0663832

Contents?: true

Size: 1.5 KB

Versions: 2

Compression:

Stored size: 1.5 KB

Contents

module AutomateEm

	#
	# Base class for all control logic classes
	#
	class Logic
		include Status
		include Constants
		include Utilities
		
		def initialize(system)
			@system = system
			
			#
			# Status variables
			#	NOTE:: if changed then change in device.rb 
			#
			@status = {}
			@status_lock = Object.new.extend(MonitorMixin)
			@status_emit = {}	# status => condition_variable
		end
		

		def logger
			@system.logger
		end
		
		
		def clear_active_timers
			@schedule.clear_jobs unless @schedule.nil?
		end

		
		protected
		

		def setting(name)
			val = LogicModule.lookup(self).settings.where("name = ?", name).first
			if val.nil?
				val = LogicModule.lookup(self).control_system.zones.joins(:settings).where('settings.name = ?', name.to_s).first
				val = val.settings.where("name = ?", name.to_s).first unless val.nil?
				
				val = LogicModule.lookup(self).dependency.settings.where("name = ?", name).first if val.nil?
			end
			
			if val.present?
				case val.value_type
					when 0
						return val.text_value
					when 1
						return val.integer_value
					when 2
						return val.float_value
					when 3
						return val.datetime_value
				end
			end
			
			return nil
		end
		

		attr_reader :system
		
		
		def register(mod, status, &block)
			@system.communicator.register(self, mod, status, &block) 
		end
		
		def unregister(mod, status, &block)
			@system.communicator.unregister(self, mod, status, &block) 
		end

		
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
automate-em-0.0.4 lib/automate-em/logic/logic.rb
automate-em-0.0.3 lib/automate-em/logic/logic.rb