 module.exports = class InsteonAdapter extends Adapter
   name: "Insteon Cloud"
   defaults:
-    initialStatusCheck:   true # Check status on all devices upon connection?
-    statusCheckInterval:  900  # Time between automatic status refreshes
-                               # in seconds. Set null to disable.
-    streamCycleInterval:  600  # How long (s) after receiving a message to close
-                               # and reopen the stream to ensure it is working.
-                               # Set null to disable.
-    batchCommandInterval: 2000 # How long to wait between repeated commands (ms)
-    devices:              {}   # Provide options for individual devices by ID.
-                               # - forwardTo: redirects all status messages from
-                               #   the device to a specified device. Useful for
-                               #   controllers. Also excludes the forwarded
-                               #   device from bulk status checks.
-                               # - class: Specify the device class for an IOLinc
-                               #   device, which determines its behavior and the
-                               #   aspects it exposes.
+    initialStatusCheck:   true  # Check status on all devices upon connection?
+    statusCheckInterval:  900   # Time between automatic status refreshes
+                                # in seconds. Set null to disable.
+    streamCycleInterval:  600   # How long (sec) after receiving a message to
+                                # close and reopen the stream to ensure it is
+                                # working. Set null to disable.
+    reconnectInterval:    86400 # How long (sec) between reauthorizations to
+                                # avoid expiration of credentials.
+    batchCommandInterval: 2000  # How long to wait between commands (ms)
+    devices:              {}    # Provide options for individual devices by ID.
+                                # - forwardTo: redirects all status messages
+                                #   from the device to a specified device.
+                                #   Useful for controllers. Also excludes the
+                                #   forwarded device from bulk status checks.
+                                # - classify: Specify the device class for an
+                                #   IOLinc device, which determines its behavior
+                                #   and the aspects it exposes.
 
   initialize: ->
     super

      @_resetStreamCycle()
    @_api.on 'error', (e) => @log 'warn', "An Insteon error occurred: #{JSON.stringify(e)}"
    @_api.on 'command', (cmd) => @_handleCommandReceived(cmd)

  discoverDevices: ->
    @_api.house().then (houses) => @_house = houses[0]

  start: ->
    @_api = new InsteonAPI(key: @get('apiKey'))
    @log "debug", "Authenticating to Insteon API with username #{@get('username')}"
    @connect()
    @_api.on 'connect', =>
      @log 'debug', 'Authenticated to Insteon API'
      if @hasDiscovered
