12-08-2013, 20:36:10
Hi zusammen,
hier ein Code-Ausschnitt, funktioniert prima ...
# -*- coding: utf-8 -*-
require 'siri_objects'
require 'rubygems'
require 'mechanize'
require 'timeout'
require 'cora'
require 'pp'
class SiriProxy:lugin::Smarthome < SiriProxy:lugin
attr_accessor :Benutzername
attr_accessor asswort
def initialize(config = {})
@sh_username = config['Benutzername']
@sh_password = config['Passwort']
@sh_root_uri = 'https://mobile.rwe-smarthome.de/MobileWeb'
@sh_login_uri = URI @sh_root_uri + '/Logon/Logon'
########## Commands
listen_for /smarthome (an|anmelden)/i do
login_rwe_smarthome
end
########## Actions
def login_rwe_smarthome
say "Einen Augenblick bitte!"
Thread.new {
begin
Timeout::timeout(30) do
begin
sh_page = @sh_session.get( @sh_login_uri )
rescue Mechanize::ResponseCodeError => e
say "Der RWE Web-Dienst ist zur Zeit nicht erreichbar! Status #{e.response_code}"
end
begin
sh_form = sh_page.forms.first
sh_form.UserName = @sh_username
sh_form.Password = @sh_password
sh_page = @sh_session.submit( sh_form, sh_form.buttons.first )
rescue Mechanize::ResponseCodeError => e
say "Die Anmeldung beim RWE Web-Dienst ist fehlgeschlagen! Status #{e.response_code}"
request_completed
end
say "Ok, die RWE SmartHome Automation ist jetzt aktiviert!"
request_completed
end
rescue Timeout::Error
say "Die Anmeldung bei dem RWE Web-Dienst ist zur Zeit nicht möglich!"
request_completed
end
}
end
end
hier ein Code-Ausschnitt, funktioniert prima ...
# -*- coding: utf-8 -*-
require 'siri_objects'
require 'rubygems'
require 'mechanize'
require 'timeout'
require 'cora'
require 'pp'
class SiriProxy:lugin::Smarthome < SiriProxy:lugin
attr_accessor :Benutzername
attr_accessor asswort
def initialize(config = {})
@sh_username = config['Benutzername']
@sh_password = config['Passwort']
@sh_root_uri = 'https://mobile.rwe-smarthome.de/MobileWeb'
@sh_login_uri = URI @sh_root_uri + '/Logon/Logon'
########## Commands
listen_for /smarthome (an|anmelden)/i do
login_rwe_smarthome
end
########## Actions
def login_rwe_smarthome
say "Einen Augenblick bitte!"
Thread.new {
begin
Timeout::timeout(30) do
begin
sh_page = @sh_session.get( @sh_login_uri )
rescue Mechanize::ResponseCodeError => e
say "Der RWE Web-Dienst ist zur Zeit nicht erreichbar! Status #{e.response_code}"
end
begin
sh_form = sh_page.forms.first
sh_form.UserName = @sh_username
sh_form.Password = @sh_password
sh_page = @sh_session.submit( sh_form, sh_form.buttons.first )
rescue Mechanize::ResponseCodeError => e
say "Die Anmeldung beim RWE Web-Dienst ist fehlgeschlagen! Status #{e.response_code}"
request_completed
end
say "Ok, die RWE SmartHome Automation ist jetzt aktiviert!"
request_completed
end
rescue Timeout::Error
say "Die Anmeldung bei dem RWE Web-Dienst ist zur Zeit nicht möglich!"
request_completed
end
}
end
end