Exemplo n.º 1
0
def setup_platform(hass, config: ConfigType,
                   add_devices: Callable[[list], None], discovery_info=None):
    """Set up the Sesame platform."""
    import pysesame

    email = config.get(CONF_EMAIL)
    password = config.get(CONF_PASSWORD)

    add_devices([SesameDevice(sesame) for
                 sesame in pysesame.get_sesames(email, password)])
Exemplo n.º 2
0
	def runConcurrentThread(self):
		self.mylogger.log(3, u"runConcurrentThread called")

		# While Indigo hasn't told us to shutdown
		while self.shutdownnow is False:

			self.nextUpdateIn -= 1

			if self.state == self.States.STARTUP:
				self.mylogger.log(3, u"STATE: Startup")

				if self.configRead is False:
					if self.getConfiguration(self.pluginPrefs) is True:
						self.configRead = True

				if self.configRead is True:
					self.mylogger.log(1, u'Logging into Candy House server.')
					self.candyAccount = pysesame.account()
					if self.candyAccount.login(self.configEmail, self.configPass) == True:
						self.sesames = pysesame.get_sesames(self.candyAccount)
						self.mylogger.log(1, u'Login succesful.  Found %d Sesame(s) in your account.' % len(self.sesames))
						for s in self.sesames:
							if s.api_enabled == False:
								self.mylogger.logError(u"Warning.  Sesame '%s' is not enabled for API access." % s.nickname)

						self.updateSesameDeviceStates()
						self.nextUpdateIn = self.kSesameUpdateDelay
						self.state = self.States.IDLE
					else:
						self.mylogger.logError(u'Login failed.  Will try again in 30 seconds.')
						self.nextUpdateIn = 30
						self.state = self.States.DELAY

			elif self.state == self.States.DELAY:
				self.mylogger.log(3, u"STATE: Delay")	
				if self.configRead is False:
					self.state = self.States.STARTUP			
				if self.nextUpdateIn <= 0:
					self.state = self.States.STARTUP

			elif self.state == self.States.IDLE:
				#self.mylogger.log(3, u"STATE: Idle")				
				if self.configRead is False:
					self.state = self.States.STARTUP
		
				if self.nextUpdateIn <= 0:
					self.sesames = pysesame.get_sesames(self.candyAccount)
					self.updateSesameDeviceStates()

					while len(self.confirmList) > 0:
						(devid, state) = self.confirmList.popitem()
						dev = indigo.devices[devid]
						if state != dev.onState:
							self.mylogger.logError(u"Sesame '%s' still hasn't changed to the requested state." % dev.name)
							self.triggerEvent(u'eventFailedToChange')
						else:
							self.mylogger.log(1, u"Sesame '%s' successfully changed state." % dev.name)

					self.nextUpdateIn = self.kSesameUpdateDelay

			# loop delay
			self.sleep(1)

		self.mylogger.log(3, u"Exiting Concurrent Thread")