from components.aheater import AHeater
from components.actor.hendiCtrl import HendiCtrl


class HeaterHendi(AHeater):
	def __init__(self, params):
		AHeater.__init__(self)
		self.hendi = HendiCtrl(params['port'], params['speed'])
		self.power_set = 0
		self.power_eff = 0

	def get_power_min(self):
		return 0

	def get_power_max(self):
		caps = self.hendi.getCapabilties()
		return caps['pwr_watts_max']

	def get_powers(self):
		caps = self.hendi.getCapabilties()
		return [0] + caps['pwr_list']

	def activate(self, enable):
		if enable:
			self.hendi.remoteEnable(1)
		else:
			self.hendi.remoteEnable(0)

	def is_activated(self):
		s = self.hendi.isRemoteEnable()
		return '1' in s

	def process(self):
		power = self.power_set
		if power == 0:
			self.hendi.setSwitch(0)
		else:
			self.hendi.setSwitch(1)
		self.hendi.setPowerWatts(power)
		self.power_eff = self.hendi.getPowerWatts() if power > 0 else 0

	def set_power(self, power):
		self.power_set = min(self.get_power_max(), power)

	def get_power(self):
		return self.power_eff
