Class: SmarterMeter::Interfaces::Wizard::GooglePowerMeterPage

Inherits:
Object
  • Object
show all
Includes:
WizardPage
Defined in:
lib/smartermeter/interfaces/swing.rb

Instance Method Summary collapse

Methods included from WizardPage

#build, #header

Constructor Details

#initialize(buttons) ⇒ GooglePowerMeterPage

Returns a new instance of GooglePowerMeterPage.



405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# File 'lib/smartermeter/interfaces/swing.rb', line 405

def initialize(buttons)
  @buttons = buttons

  title = "<html><b>Connect to Google PowerMeter</b></html>"
  message  = "In order to view your power data on Google PowerMeter you'll need to create an account."

  header(title, message) do |c|
    layout = "
        [ create ]
        [ auth_label ]
        [ auth_field ]
    "
    @controls = Profligacy::Swing::LEL.new(JPanel, layout) do |cc,ii|
      cc.create = JButton.new "Create a PowerMeter Account"
      ii.create = { :action => method(:open_google_powermeter_registration) }
      cc.auth_label = JLabel.new "Then, copy your Authorization Information below:"
      cc.auth_field = JTextArea.new
      cc.auth_field.line_wrap = true
      cc.auth_field.minimum_size = Dimension.new(400, 80)
      cc.auth_field.maximum_size = Dimension.new(400, 80)
      ii.auth_field = { :key => method(:validate) }
    end
    c.controls = @controls.build
  end
end

Instance Method Details

#authObject



439
440
441
# File 'lib/smartermeter/interfaces/swing.rb', line 439

def auth
  @controls.auth_field.text.strip
end

#open_google_powermeter_registration(*ignored_args) ⇒ Object

Opens the Google Powermeter registration flow so that users can upload their data.

Returns nothing.



447
448
449
450
451
# File 'lib/smartermeter/interfaces/swing.rb', line 447

def open_google_powermeter_registration(*ignored_args)
    desktop = Desktop.getDesktop()
    uri = Java::JavaNet::URI.new("https://www.google.com/powermeter/device/activate?mfg=SmarterMeter&model=SmarterMeter&did=PGE&dvars=1")
    desktop.browse(uri)
end

#tokenObject



431
432
433
# File 'lib/smartermeter/interfaces/swing.rb', line 431

def token
  CGI.parse(@controls.auth_field.text.strip)["token"][0]
end

#validate(*ignored_args) ⇒ Object

Determines whether a user has entered authorization information from Google.

Returns nothing.



457
458
459
# File 'lib/smartermeter/interfaces/swing.rb', line 457

def validate(*ignored_args)
  @buttons.next.enabled = @controls.auth_field.text.size > 0
end

#variableObject



435
436
437
# File 'lib/smartermeter/interfaces/swing.rb', line 435

def variable
  CGI.parse(@controls.auth_field.text.strip)["path"][0]+".d1"
end