Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

siriproxy plugin initialization #485

Open
@elvisimprsntr

Description

Beginning with SP 0.4.2 (with the new plugin_init), I have observed a problem where code in the initialization section gets run upon start of siriproxy server, not just upon a siri connection. Perhaps it has always been this way, but it was presenting a challenge with one of my plugins which I was implementing auto discovery. I was able to work around the issue by making all initialization class variables and removed them from the initialization section. I tried to use the new plugin_init, but it seems to make initialization more difficult to understand and manage. Perhaps I did not fully grasp how to use the new plugin_init method. Not sure if anyone else has observed or has similar problems.

require 'dnssd'
require 'socket'
require 'httparty'
require 'yaml'

class SiriProxy::Plugin::RedEye < SiriProxy::Plugin

class Rest
include HTTParty
format :xml
end

####### Initialization

@@REIP = Hash.new
DNSSD.browse '_tf_redeye._tcp.' do |reply|
puts "[Info - Redeye] Bonjour discovery: " + reply.name
addr = Socket.getaddrinfo(reply.name + ".local.", nil, Socket::AF_INET)
@@REIP[reply.name] = addr[0][2]
end

begin
@@default = YAML.load(File.read(File.expand_path(File.dirname( FILE ) + "/reDefault.yml")))
@@stationID = YAML.load(File.read(File.expand_path(File.dirname( FILE ) + "/reStation.yml")))
rescue
puts "[Warning - RedEye] Error reading reDefault.yml and/or reStation.yml file."
end

begin
@@Resel = YAML.load(File.read(File.expand_path(File.dirname( FILE ) + "/reSel.yml")))
@@redeyeIP = YAML.load(File.read(File.expand_path(File.dirname( FILE ) + "/reRedeye.yml")))
@@roomid = YAML.load(File.read(File.expand_path(File.dirname( FILE ) + "/reRoom.yml")))
@@deviceid = YAML.load(File.read(File.expand_path(File.dirname( FILE ) + "/reDevice.yml")))
@@activityID = YAML.load(File.read(File.expand_path(File.dirname( FILE ) + "/reActivity.yml")))
@@commandID = YAML.load(File.read(File.expand_path(File.dirname( FILE ) + "/reCommand.yml")))
@@cmdURL = @@redeyeIP[@@Resel["redeye"]] + @@roomid[@@Resel["redeye"]][@@Resel["room"]] + @@deviceid[@@Resel["room"]][@@Resel["device"]]
rescue
@@Resel = @@default
@@redeyeIP = Hash.new
@@roomid = Hash.new { |h,k| h[k] = Hash.new }
@@deviceid = Hash.new { |h,k| h[k] = Hash.new }
@@activityID = Hash.new { |h,k| h[k] = Hash.new }
@@commandID = Hash.new(&(p=lambda{|h,k| h[k] = Hash.new(&p)}))
puts "[Warning - RedEye] Plugin not initialized. Say RedEye Initialize."
end

def initialize(config)
# Unfortunately, anything put here gets run during SiriProxy >= 0.4.2 startup.
end

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions