|
From: <Ba...@us...> - 2012-02-17 23:12:58
|
Revision: 4456
http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=4456&view=rev
Author: BartEv
Date: 2012-02-17 23:12:46 +0000 (Fri, 17 Feb 2012)
Log Message:
-----------
- Added multi box support
- Added fallback to remote connectionType
- Move scene trigger to side action menu
- Added sort options
- Added filter options
- Add vie by category option
Modified Paths:
--------------
trunk/plugins/VeraControl/BaseDevice.cs
trunk/plugins/VeraControl/DevCategories.cs
trunk/plugins/VeraControl/DeviceCam.cs
trunk/plugins/VeraControl/DeviceDimmer.cs
trunk/plugins/VeraControl/DeviceDoorlock.cs
trunk/plugins/VeraControl/DeviceGWeather.cs
trunk/plugins/VeraControl/DeviceGeneric.cs
trunk/plugins/VeraControl/DeviceHumidity.cs
trunk/plugins/VeraControl/DeviceLightSensor.cs
trunk/plugins/VeraControl/DevicePowerMeter.cs
trunk/plugins/VeraControl/DeviceSceneController.cs
trunk/plugins/VeraControl/DeviceSecurity.cs
trunk/plugins/VeraControl/DeviceSprinkler.cs
trunk/plugins/VeraControl/DeviceSwitch.cs
trunk/plugins/VeraControl/DeviceSystem.cs
trunk/plugins/VeraControl/DeviceTemperature.cs
trunk/plugins/VeraControl/DeviceThermostat.cs
trunk/plugins/VeraControl/DeviceWindowCovering.cs
trunk/plugins/VeraControl/DialogActionTrigger.cs
trunk/plugins/VeraControl/DialogDeviceControl.cs
trunk/plugins/VeraControl/Room.cs
trunk/plugins/VeraControl/Scene.cs
trunk/plugins/VeraControl/Section.cs
trunk/plugins/VeraControl/VeraCommunication.cs
trunk/plugins/VeraControl/VeraControl.cs
trunk/plugins/VeraControl/VeraControl.csproj
trunk/plugins/VeraControl/VeraSetupForm.Designer.cs
trunk/plugins/VeraControl/VeraSetupForm.cs
trunk/plugins/VeraControl/skin/Default/VeraControl.xml
trunk/plugins/VeraControl/skin/DefaultWide/VeraControl.xml
Modified: trunk/plugins/VeraControl/BaseDevice.cs
===================================================================
--- trunk/plugins/VeraControl/BaseDevice.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/BaseDevice.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -18,22 +18,23 @@
/// </summary>
public class BaseDevice
{
- private long _lastUpdate = 0;
- private long _lastPendingUpdate = 0;
- private bool _screenUpdateRequired = false;
- private string _name = "unknown device";
- private int _id = 0;
- private int _room = 0;
+ private long _lastUpdate = 0;
+ private long _lastPendingUpdate = 0;
+ private bool _screenUpdateRequired = false;
+ private string _name = "unknown device";
+ private int _id = 0;
+ private int _room = 0;
// not connected (-2), none (-1), pending (0,1,5,6), success(4), error (2,3)
- private DevState _dsState = DevState.NONE;
- private string _comment = ""; // red(error), green(success) or blue(pending) - icon/text
+ private DevState _dsState = DevState.NONE;
+ private string _comment = ""; // red(error), green(success) or blue(pending) - icon/text
- public VeraHelper _helper = VeraHelper.Instance;
- public VeraCommunication _vera = VeraCommunication.Instance;
+ public VeraHelper _helper = VeraHelper.Instance;
+ public VeraBox _myVeraBox = null;
- public BaseDevice(XmlNode xn)
+ public BaseDevice(XmlNode xn, int veraid)
{
+ _myVeraBox = VeraCommunication.Instance.boxes[veraid];
if (xn != null)
{
Update(xn);
@@ -49,7 +50,7 @@
_id = _helper.GetAttrAsInt (xn, "id", _id);
_room = _helper.GetAttrAsInt (xn, "room", _room);
_comment = _helper.GetAttrAsString(xn, "comment", _comment );
- _dsState = _helper.ToDevState(_helper.GetAttrAsInt(xn, "state", -1));
+ _dsState = _helper.ToDevState (_helper.GetAttrAsInt(xn, "state", -1));
if (_id == 0)
{
@@ -57,6 +58,16 @@
return false;
}
+ if (room == _myVeraBox.zeroId || !_myVeraBox.status.IsRoomFound(room))
+ {
+ room = _myVeraBox.zeroId;
+ if (!_myVeraBox.status.IsRoomFound(room))
+ { // create dummy room to attach to
+ _myVeraBox.rooms.Add(new Room(null, _myVeraBox.myId));
+ _myVeraBox.rooms[_myVeraBox.rooms.Count - 1].section = _myVeraBox.rooms[0].section;
+ }
+ }
+
// Set update flag
screenUpdateRequired = true;
lastUpdate = DateTime.Now.Ticks;
@@ -75,37 +86,69 @@
public int id
{
- get { return _id; }
- set { }
+ get
+ {
+ if (_myVeraBox == null)
+ {
+ return 0;
+ }
+ return (VeraCommunication.IDMASK * _myVeraBox.myId) + _id;
+ }
}
+ public int internalId
+ {
+ get { return _id; }
+ }
+
+ /// <summary>
+ /// Unique id based on Vera's serial id, so wil also stand on vera config/id changes. Should be used when id is stored over MP session (like in config files)
+ /// </summary>
+ public long configChangeProofId
+ {
+ get
+ {
+ if (_myVeraBox == null)
+ {
+ return 0;
+ }
+ return (long)((long)VeraCommunication.IDMASK * (long)_myVeraBox.status.system.serialno) + (long)_id;
+ }
+ }
+
public string name
{
- get { return _name; }
- set { }
+ get { return _name; }
}
public bool InRoom(int id)
{
- return (_room == id);
+ return (room == id);
}
public int room
{
- get { return _room; }
- set { _room = value; }
+ get {
+ if (_myVeraBox == null)
+ {
+ return 0;
+ }
+ return _room + (VeraCommunication.IDMASK * _myVeraBox.myId);
+ }
+ set
+ {
+ _room = value % VeraCommunication.IDMASK;
+ }
}
public DevState commstate
{
get { return _dsState; }
- set { }
}
public string comment
{
get { return (commstate != DevState.NONE ? _comment : ""); }
- set { }
}
public bool screenUpdateRequired
@@ -114,7 +157,7 @@
set {
if (value)
{ // If at least one device report screen update required, Vera should take over this report
- _vera.setScreenUpdateRequired();
+ _myVeraBox.setScreenUpdateRequired();
}
_screenUpdateRequired = value;
}
Modified: trunk/plugins/VeraControl/DevCategories.cs
===================================================================
--- trunk/plugins/VeraControl/DevCategories.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/DevCategories.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -4,8 +4,8 @@
* Date: 22-12-2011
* Time: 14:14
*
- * Copyright: 2012 GPL - Bart Eversdijk
- * MediaPort plugin - MicasaVerde (TM) Vera Controller
+ * Copyright: 2012 GPL - Bart Eversdijk
+ * MediaPort plugin - MicasaVerde (TM) Vera Controller
* E-mail: ba...@ev...
*/
using System;
@@ -20,16 +20,28 @@
{
public DevCategories(XmlNode xn)
{
- if (xn != null)
+ if (xn != null)
{
Update(xn);
}
}
- private string _name = "unknown category";
- private int _id = 0;
- public VeraHelper _helper = VeraHelper.Instance;
+ public DevCategories(int id)
+ {
+ _id = id;
+ }
+ public DevCategories(int id, string nm)
+ {
+ _id = id;
+ _name = nm;
+ }
+
+ private string _name = "unknown category";
+ private int _id = 0;
+ public VeraHelper _helper = VeraHelper.Instance;
+
+
public bool Update(XmlNode xn)
{
_name = _helper.GetAttrAsString(xn, "name", _name);
@@ -40,15 +52,90 @@
public int id
{
get { return _id; }
- set { }
}
-
+
public string name
{
- get { return _name; }
- set { }
+ get { return _name; }
+ set { _name = value; }
}
+
+ public string GetIconName()
+ {
+ switch (id)
+ {
+ case 1: // Interface
+ return "USB_UIRT";
+
+ case 2: // Dimmer
+ return "Dimmable_Light_100";
+
+ case 3: // Switch
+ return "Binary_Light_100";
+
+ case 4: // Generic Sensor
+ return "generic_sensor";
+
+ case 5: // Thermostat
+ return "Thermostat";
+
+ case 6: // Web Cam
+ return "Ip_Camera";
+
+ case 7:
+ return "Door_Lock_100";
+
+ case 8: // Window covering
+ return "Window_Covering";
+
+ case 9: // Remote control
+ case 10: // Ir TX
+ return "IR_Transmitter";
+
+ case 12: // Motion Sensor
+ return "Motion_Sensor_100";
+
+ case 11: // Generic IO
+ case 13: // Serial port
+ return "Generic_IO";
+
+ case 14: // Scene controller
+ return "Scenes_active";
+
+ case 15: // AV
+ return "music_audio";
+
+ case 16: // Humidity
+ return "Humidity_Sensor";
+
+ case 17: // Temperature
+ return "Temperature_Sensor";
+
+ case 18: // Light sensor
+ return "Light_Sensor";
+
+ case 19: // Z-wave
+ return "Zwave";
+
+ case 20: // Insteon
+ return "Insteon";
+
+ case 21: // Power meter
+ return "Power_Meter";
+
+ case 101: // Special Sprinkler device not support by Vera's UI
+ return "Sprinkler";
+
+ case 102: // Special (Google) Weather device not support by Vera's UI
+ return "location";
+
+ case 0:
+ default:
+ return "generic_sensor";
+ }
+ }
+
public override string ToString()
{
return name;
Modified: trunk/plugins/VeraControl/DeviceCam.cs
===================================================================
--- trunk/plugins/VeraControl/DeviceCam.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/DeviceCam.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -24,7 +24,7 @@
private string _user = "";
private string _pass = "";
- public DeviceCam(XmlNode xn): base (xn)
+ public DeviceCam(XmlNode xn, int verabox): base (xn, verabox)
{
if (xn != null)
{
@@ -53,21 +53,18 @@
}
return _user + ":" + _pass + "@";
}
- set { }
}
public string imgUrl
{
- get { return _vera.veraAddress + "/data_request?id=cam_image¶meters=get_video_frame&Device_Num=" + id + "&rand=" + DateTime.Now.Ticks;
+ get { return _myVeraBox.veraAddress + "/data_request?id=cam_image¶meters=get_video_frame&Device_Num=" + internalId.ToString() + "&rand=" + DateTime.Now.Ticks;
// return "http://" + passString + m_sIp + "/" + m_sUrl.Replace("%2F", "/");
}
- set { }
}
public string streamUrl
{
get { return "http://" + passString + _ip + "/" + _stream.Replace("%2F", "/"); }
- set { }
}
public int refreshRate
@@ -84,14 +81,8 @@
public override bool isControllable
{
get { return true; }
- set { }
}
- public override string GetIconName()
- {
- return "Ip_Camera";
- }
-
public override bool NewScreenUpdateWaitingAndClearFlag( )
{
// Invoking this method will clear the update ready flag -> so caller need to handle the update
@@ -119,12 +110,12 @@
{
if (id == 0)
{
- _vera.status.system.ReportCommandError("Unknown device");
+ _myVeraBox.status.system.ReportCommandError("Unknown device");
screenUpdateRequired = true;
return;
}
- string cmd = "?id=lu_action&DeviceNum=" + id + "&serviceId=urn:micasaverde-com:serviceId:PanTiltZoom1&action=" + direction;
- _vera.DoVeraCommandRequest(cmd, ReportRequestError);
+ string cmd = "?id=lu_action&DeviceNum=" + internalId + "&serviceId=urn:micasaverde-com:serviceId:PanTiltZoom1&action=" + direction;
+ _myVeraBox.DoVeraCommandRequest(cmd, ReportRequestError);
}
public override void MoveUp()
Modified: trunk/plugins/VeraControl/DeviceDimmer.cs
===================================================================
--- trunk/plugins/VeraControl/DeviceDimmer.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/DeviceDimmer.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -22,7 +22,7 @@
private string _watt = "-";
private string _kwh = "-";
- public DeviceDimmer(XmlNode xn): base (xn)
+ public DeviceDimmer(XmlNode xn, int verabox): base (xn, verabox)
{
if (xn != null)
{
@@ -42,7 +42,6 @@
public string watts
{
get { return _watt; }
- set { }
}
public override bool status
@@ -66,10 +65,10 @@
{
ReportPendingRequest();
// Do something with vera
- string cmd = "?id=lu_action&DeviceNum="+id.ToString() +
+ string cmd = "?id=lu_action&DeviceNum="+internalId.ToString() +
"&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget" +
"&newLoadlevelTarget=" + value;
- _vera.DoVeraCommandRequest(cmd, ReportRequestError);
+ _myVeraBox.DoVeraCommandRequest(cmd, ReportRequestError);
}
_level = newValue;
}
@@ -78,7 +77,6 @@
public override int maxLevel
{
get { return 100; }
- set { }
}
public override string ToString()
@@ -89,7 +87,6 @@
public override bool isControllable
{
get { return true; }
- set { }
}
public override string GetIconName()
@@ -105,12 +102,49 @@
public override string GetExtraText()
{
- return (_kwh != "" ? _kwh + "kWh" : "");
+ return ((_kwh != "" && _kwh != "-") ? "Power usage " + _kwh + " kWh" : "");
}
public override string GetStatusText()
{
return (status ? level.ToString() + "%" : "Off");
}
+
+ public override string mode
+ {
+ get {
+ string strmode = "Off";
+ if (level > 0) { strmode = "25%"; }
+ if (level > 25) { strmode = "50%"; }
+ if (level > 50) { strmode = "75%"; }
+ if (level > 75) { strmode = "0n"; }
+ return strmode;
+ }
+ set {
+ switch (value)
+ {
+ case "Off":
+ level = 0;
+ break;
+ case "25%":
+ level = 25;
+ break;
+ case "50%":
+ level = 50;
+ break;
+ case "75%":
+ level = 75;
+ break;
+ case "On":
+ level = 100;
+ break;
+ }
+ }
+ }
+
+ public override string [] GetCommands()
+ {
+ return new string [] {"Off", "On", "25%", "75%", "50%"};
+ }
}
}
Modified: trunk/plugins/VeraControl/DeviceDoorlock.cs
===================================================================
--- trunk/plugins/VeraControl/DeviceDoorlock.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/DeviceDoorlock.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -20,7 +20,7 @@
{
private bool _status = false;
- public DeviceDoorlock( XmlNode xn ): base (xn)
+ public DeviceDoorlock( XmlNode xn, int verabox ): base (xn, verabox)
{
if (xn != null)
{
@@ -43,10 +43,10 @@
{
ReportPendingRequest();
// Do something with vera
- string cmd = "?id=lu_action&DeviceNum="+id.ToString()+
+ string cmd = "?id=lu_action&DeviceNum="+internalId.ToString()+
"&serviceId=urn:micasaverde-com:serviceId:DoorLock1&action=SetTarget" +
"&newTargetValue="+(value ? "1" : "0");
- _vera.DoVeraCommandRequest(cmd, ReportRequestError);
+ _myVeraBox.DoVeraCommandRequest(cmd, ReportRequestError);
}
}
}
@@ -63,7 +63,6 @@
public override int maxLevel
{
get { return 1; }
- set { }
}
public override string ToString()
@@ -74,7 +73,6 @@
public override bool isControllable
{
get { return true; }
- set { }
}
public override string GetIconName()
Modified: trunk/plugins/VeraControl/DeviceGWeather.cs
===================================================================
--- trunk/plugins/VeraControl/DeviceGWeather.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/DeviceGWeather.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -21,7 +21,7 @@
private string _condition = "-";
private string _windCondition = "-";
- public DeviceGWeather(XmlNode xn): base (xn)
+ public DeviceGWeather(XmlNode xn, int verabox): base (xn, verabox)
{
if (xn != null)
{
@@ -35,8 +35,15 @@
_condition = _helper.GetAttrAsString(xn, "condition", _condition); // World Weather plugin
_windCondition = _helper.GetAttrAsString(xn, "WindCondition", _windCondition);
_windCondition = _helper.GetAttrAsString(xn, "windcondition", _windCondition);
+
+ bool ret = base.Update(xn);
+ category = 102; // Override Vera's Cateogry with Speical ID code
- return base.Update(xn);
+ if (!_myVeraBox.status.IsCategoryFound(category))
+ { // create this category if it does not exists
+ _myVeraBox.categories.Add(new DevCategories(category, "Weather"));
+ }
+ return ret;
}
public override string ToString()
Modified: trunk/plugins/VeraControl/DeviceGeneric.cs
===================================================================
--- trunk/plugins/VeraControl/DeviceGeneric.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/DeviceGeneric.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -10,6 +10,7 @@
*/
using System;
using System.Xml;
+using System.Collections;
using System.Collections.Generic;
namespace VeraControl.Properties
@@ -23,7 +24,7 @@
private int _category = 0;
private int _stepsize = 0;
- public DeviceGeneric(XmlNode xn): base (xn)
+ public DeviceGeneric(XmlNode xn, int verabox): base (xn, verabox)
{
if (xn != null)
{
@@ -40,33 +41,53 @@
_altId = _helper.GetAttrAsString(xn, "altid", _altId);
_category = _helper.GetAttrAsInt (xn, "category", _category);
- bool b = base.Update(xn);
- // Make sure the room exists
- if (room == 0 || !_vera.status.IsRoomFound(room))
+ return base.Update(xn);
+ }
+
+ public bool PassesFilter(VeraFilterStyle filter)
+ {
+ switch (filter)
{
- if (!_vera.status.IsRoomFound(0))
- { // create dummy room to attach to
- _vera.rooms.Add(new Room(null));
- }
- room = 0;
+ case VeraFilterStyle.UNKNOWN_DEVICES:
+ return isControllable|| !new ArrayList(new int [] {0}).Contains(category);
+
+ case VeraFilterStyle.GENERIC_DEVICES:
+ return isControllable || !new ArrayList(new int [] {0,1,11,12}).Contains(category);
+
+ case VeraFilterStyle.REMOTE_DEVICES:
+ return isControllable || !new ArrayList(new int [] {0,1,10,11,12,13,15,19,20}).Contains(category);
+
+ case VeraFilterStyle.SCENE_CONTROLLERS:
+ return isControllable || !new ArrayList(new int [] {0,1,10,11,12,13,14,15,19,20}).Contains(category);
+
+ case VeraFilterStyle.CONTROLABLE_ONLY:
+ return isControllable;
+
+ default:
+ case VeraFilterStyle.NONE:
+ return true;
}
- return b;
}
-
+
public string altid
{
get { return _altId; }
}
-
+
+ public bool InCategory(int id)
+ {
+ return (category == id);
+ }
+
public int category
{
get { return _category; }
+ set { _category = value; }
}
public virtual bool isControllable
{
get { return false; }
- set { }
}
public virtual bool status
@@ -92,7 +113,7 @@
if (stepSize > 0)
{
level += stepSize;
- }
+ }
}
public virtual void DecreaseLevel()
@@ -100,7 +121,7 @@
if (stepSize > 0)
{
level -= stepSize;
- }
+ }
}
public virtual string mode
@@ -123,7 +144,7 @@
public override string GetIconName()
{
- return "generic_sensor";
+ return new DevCategories(category).GetIconName();
}
public override string GetStatusText()
Modified: trunk/plugins/VeraControl/DeviceHumidity.cs
===================================================================
--- trunk/plugins/VeraControl/DeviceHumidity.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/DeviceHumidity.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -20,7 +20,7 @@
{
private int _level = 0;
- public DeviceHumidity(XmlNode xn) : base (xn)
+ public DeviceHumidity(XmlNode xn, int verabox) : base (xn, verabox)
{
if (xn != null)
{
@@ -37,13 +37,11 @@
public override int level
{
get { return _level; }
- set {}
}
public override int maxLevel
{
get { return 100; }
- set { }
}
public override string ToString()
@@ -51,11 +49,6 @@
return name + " [" + level.ToString() + "%]";
}
- public override string GetIconName()
- {
- return "Humidity_Sensor";
- }
-
public override string GetStatusText()
{
return level + "%";
Modified: trunk/plugins/VeraControl/DeviceLightSensor.cs
===================================================================
--- trunk/plugins/VeraControl/DeviceLightSensor.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/DeviceLightSensor.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -20,7 +20,7 @@
{
private int _level = 0;
- public DeviceLightSensor(XmlNode xn) : base (xn)
+ public DeviceLightSensor(XmlNode xn, int verabox) : base (xn, verabox)
{
if (xn != null)
{
@@ -38,19 +38,16 @@
public override bool status
{
get { return (_level > 0); }
- set { }
}
public override int level
{
get { return _level; }
- set { }
}
public override int maxLevel
{
get { return 100; }
- set { }
}
public override string ToString()
Modified: trunk/plugins/VeraControl/DevicePowerMeter.cs
===================================================================
--- trunk/plugins/VeraControl/DevicePowerMeter.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/DevicePowerMeter.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -21,7 +21,7 @@
private int _level = 0;
private string _kwh = "";
- public DevicePowerMeter(XmlNode xn) : base (xn)
+ public DevicePowerMeter(XmlNode xn, int verabox) : base (xn, verabox)
{
if (xn != null)
{
@@ -39,25 +39,21 @@
public string watts
{
get { return _level.ToString(); }
- set { }
}
public override bool status
{
get { return (_level > 0); }
- set { }
}
public override int level
{
get { return _level; }
- set { }
}
public override int maxLevel
{
get { return 1000; }
- set { }
}
public override string ToString()
@@ -65,14 +61,9 @@
return name + " [" + GetStatusText() + "]";
}
- public override string GetIconName()
- {
- return "Power_Meter";
- }
-
public override string GetExtraText()
{
- return (_kwh != "" ? _kwh + "kWh" : "");
+ return ((_kwh != "" && _kwh != "-") ? "Power usage " + _kwh + " kWh" : "");
}
public override string GetStatusText()
Modified: trunk/plugins/VeraControl/DeviceSceneController.cs
===================================================================
--- trunk/plugins/VeraControl/DeviceSceneController.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/DeviceSceneController.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -18,7 +18,7 @@
{
private bool _isTripped = false;
- public DeviceSceneController( XmlNode xn ) : base (xn)
+ public DeviceSceneController( XmlNode xn, int verabox ) : base (xn, verabox)
{
if (xn != null)
{
@@ -36,19 +36,16 @@
public override bool status
{
get { return _isTripped; }
- set { }
}
public bool isTripped
{
get { return _isTripped; }
- set { }
}
public override int level
{
get { return (_isTripped ? 1 : 0); }
- set { }
}
public override string ToString()
@@ -58,7 +55,7 @@
public override string GetIconName()
{
- return "Motion_Sensor_" + (_isTripped ? "100" : "0");
+ return "Scenes" + (_isTripped ? "_active" : "");
}
public override string GetStatusText()
Modified: trunk/plugins/VeraControl/DeviceSecurity.cs
===================================================================
--- trunk/plugins/VeraControl/DeviceSecurity.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/DeviceSecurity.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -22,7 +22,7 @@
private bool _isTripped = false;
private bool _isArmed = true;
- public DeviceSecurity(XmlNode xn) : base (xn)
+ public DeviceSecurity(XmlNode xn, int verabox) : base (xn, verabox)
{
if (xn != null)
{
@@ -45,10 +45,10 @@
{
ReportPendingRequest();
// Do something with vera
- string cmd = "?id=lu_action&DeviceNum="+id.ToString()+
+ string cmd = "?id=lu_action&DeviceNum=" + internalId.ToString() +
"&serviceId=urn:micasaverde-com:serviceId:SecuritySensor1&action=SetArmed" +
"&newArmedValue=" + (value ? "1" : "0");
- _vera.DoVeraCommandRequest(cmd, ReportRequestError);
+ _myVeraBox.DoVeraCommandRequest(cmd, ReportRequestError);
}
}
}
@@ -56,7 +56,6 @@
public bool isTripped
{
get { return _isTripped; }
- set { }
}
public override int level
@@ -68,13 +67,11 @@
public override int maxLevel
{
get { return 1; }
- set { }
}
public override bool isControllable
{
get { return true; }
- set { }
}
public override string ToString()
Modified: trunk/plugins/VeraControl/DeviceSprinkler.cs
===================================================================
--- trunk/plugins/VeraControl/DeviceSprinkler.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/DeviceSprinkler.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -4,8 +4,8 @@
* Date: 3-1-2012
* Time: 16:26
*
- * Copyright: 2012 GPL - Bart Eversdijk
- * MediaPort plugin - MicasaVerde (TM) Vera Controller
+ * Copyright: 2012 GPL - Bart Eversdijk
+ * MediaPort plugin - MicasaVerde (TM) Vera Controller
* E-mail: ba...@ev...
*/
using System;
@@ -25,7 +25,7 @@
private string _operationMode = "-";
private string _condition = "-";
- public DeviceSprinkler(XmlNode xn) : base (xn)
+ public DeviceSprinkler(XmlNode xn, int verabox) : base (xn, verabox)
{
if (xn != null)
{
@@ -33,29 +33,39 @@
}
}
- public override bool Update(XmlNode xn)
+ public override bool Update(XmlNode xn)
{
_status = _helper.GetAttrAsBool (xn, "status", _status);
_mode = _helper.GetAttrAsString(xn, "Mode", _mode);
_shortMode = _helper.GetAttrAsString(xn, "ShortMode", _shortMode);
_operationMode = _helper.GetAttrAsString(xn, "OperationMode", _operationMode);
_condition = _helper.GetAttrAsString(xn, "Condition", _condition);
- return base.Update(xn);
+
+ bool ret = base.Update(xn);
+ category = 101; // Override Vera's Cateogry with Speical ID code
+
+ if (!_myVeraBox.status.IsCategoryFound(category))
+ {
+ // create this category if it does not exists
+ _myVeraBox.categories.Add(new DevCategories(category, "Sprinklers"));
+ }
+
+ return ret;
}
public override bool status
{
get { return _status; }
- set {
- if (id > 0) // Only send when a valid ID is found
- {
- ReportPendingRequest();
- // Do something with vera
- string cmd = "?id=lu_action&DeviceNum="+id.ToString()+
- "&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget" +
- "&newTargetValue="+(value ? "1" : "0");
- _vera.DoVeraCommandRequest(cmd, ReportRequestError);
- }
+ set {
+ if (id > 0) // Only send when a valid ID is found
+ {
+ ReportPendingRequest();
+ // Do something with vera
+ string cmd = "?id=lu_action&DeviceNum=" + internalId.ToString() +
+ "&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget" +
+ "&newTargetValue="+(value ? "1" : "0");
+ _myVeraBox.DoVeraCommandRequest(cmd, ReportRequestError);
+ }
}
}
@@ -68,16 +78,16 @@
public override string mode
{
get { return _mode; }
- set {
- if (id > 0) // Only send when a valid ID is found
- {
- ReportPendingRequest();
- // Do something with vera
- string cmd = "?id=lu_action&DeviceNum="+id.ToString()+
- "&serviceId=urn:upnp-micasaverde-com:serviceId:Sprinkler1&action=" +
- (value == "Auto" ? "SetModeAuto" : (value == "Block" ? "SetModeBlock" : "SetModeManual"));
- _vera.DoVeraCommandRequest(cmd, ReportRequestError);
- }
+ set {
+ if (id > 0) // Only send when a valid ID is found
+ {
+ ReportPendingRequest();
+ // Do something with vera
+ string cmd = "?id=lu_action&DeviceNum=" + internalId.ToString() +
+ "&serviceId=urn:upnp-micasaverde-com:serviceId:Sprinkler1&action=" +
+ (value == "Auto" ? "SetModeAuto" : (value == "Block" ? "SetModeBlock" : "SetModeManual"));
+ _myVeraBox.DoVeraCommandRequest(cmd, ReportRequestError);
+ }
}
}
@@ -89,19 +99,12 @@
public override bool isControllable
{
get { return true; }
- set { }
}
public override int maxLevel
{
get { return 1; }
- set { }
}
-
- public override string GetIconName()
- {
- return "Sprinkler";
- }
public override string GetStatusText()
{
Modified: trunk/plugins/VeraControl/DeviceSwitch.cs
===================================================================
--- trunk/plugins/VeraControl/DeviceSwitch.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/DeviceSwitch.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -22,7 +22,7 @@
private string _watt = "-";
private string _kwh = "-";
- public DeviceSwitch(XmlNode xn) : base (xn)
+ public DeviceSwitch(XmlNode xn, int verabox) : base (xn, verabox)
{
if (xn != null)
{
@@ -42,7 +42,6 @@
public string watts
{
get { return _watt; }
- set { }
}
public override bool status
@@ -53,10 +52,10 @@
{
ReportPendingRequest();
// Do something with vera
- string cmd = "?id=lu_action&DeviceNum="+id.ToString()+
+ string cmd = "?id=lu_action&DeviceNum=" + internalId.ToString() +
"&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget" +
"&newTargetValue="+(value ? "1" : "0");
- _vera.DoVeraCommandRequest(cmd, ReportRequestError);
+ _myVeraBox.DoVeraCommandRequest(cmd, ReportRequestError);
}
}
}
@@ -70,7 +69,6 @@
public override int maxLevel
{
get { return 1; }
- set { }
}
public override string ToString()
@@ -81,7 +79,6 @@
public override bool isControllable
{
get { return true; }
- set { }
}
public override string GetIconName()
@@ -91,7 +88,7 @@
public override string GetExtraText()
{
- return (_kwh != "" ? _kwh + "kWh" : "");
+ return ((_kwh != "" && _kwh != "-") ? "Power usage " + _kwh + " kWh" : "");
}
public override string GetStatusText()
Modified: trunk/plugins/VeraControl/DeviceSystem.cs
===================================================================
--- trunk/plugins/VeraControl/DeviceSystem.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/DeviceSystem.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -26,12 +26,12 @@
public long _lastUpdate = 0;
public bool _screenUpdateRequired = false;
private bool _fullReload = true;
- private string _version = "";
+ private string _version = "-";
private string _model = "";
private bool _zWaveHeal = false;
private bool _metric = true;
- private string _serial = "";
- private string _fwd1Server = "";
+ private int _serial = -1;
+ private string _fwd1Server = "-";
private string _fwd2Server = "";
private string _loadTime = "0";
private string _dataVersion = "0";
@@ -43,22 +43,22 @@
{
_fullReload = _helper.GetAttrAsBool (xn, "full", _fullReload);
_version = _helper.GetAttrAsString(xn, "version", _version);
+ _serial = _helper.GetAttrAsInt (xn, "serial_number", _serial);
_model = _helper.GetAttrAsString(xn, "model", _model);
_zWaveHeal = _helper.GetAttrAsBool (xn, "zwave_heal", _zWaveHeal);
- _serial = _helper.GetAttrAsString(xn, "serial_number", _serial);
_fwd1Server = _helper.GetAttrAsString(xn, "fwd1", _fwd1Server);
_fwd2Server = _helper.GetAttrAsString(xn, "fwd2", _fwd2Server);
_loadTime = _helper.GetAttrAsString(xn, "loadtime", _loadTime);
// Set update flag
- string tempDataversion = _helper.GetAttrAsString (xn, "dataversion", _dataVersion);
- DevState tempVeraState = _helper.ToDevState(_helper.GetAttrAsInt(xn, "state", -1));
- string tempComment = _helper.GetAttrAsString (xn, "comment", "");
+ string tempDataversion = _helper.GetAttrAsString (xn, "dataversion", _dataVersion);
+ DevState tempVeraState = _helper.ToDevState(_helper.GetAttrAsInt(xn, "state", -1));
+ string tempComment = _helper.GetAttrAsString (xn, "comment", "");
if ((_dataVersion != tempDataversion) || _comment != tempComment || _dsVeraState != tempVeraState)
{
_screenUpdateRequired = true;
- _lastUpdate = DateTime.Now.Ticks;
+ _lastUpdate = DateTime.Now.Ticks;
}
_dataVersion = tempDataversion;
_dsVeraState = tempVeraState;
@@ -91,61 +91,51 @@
public bool fullReload
{
get { return _fullReload; }
- set { }
}
public string versionInfo
{
get { return _model + " " + _version; }
- set { }
}
public bool zWaveHeal
{
get { return _zWaveHeal; }
- set { }
}
- public string serialno
+ public int serialno
{
get { return _serial; }
- set { }
}
public string fwd
{
get { return _fwd1Server; }
- set { }
}
public string fwdBackup
{
get { return _fwd2Server; }
- set { }
}
public string loadtime
{
get { return _loadTime; }
- set { }
}
public string dataversion
{
get { return _dataVersion; }
- set { }
}
public DevState state
{
- get { return _dsVeraState; }
- set { }
+ get { return (serialno == -1 ? DevState.CONNECTION_ERROR :_dsVeraState); }
}
public string comment
{
- get { return _comment; }
- set { }
+ get { return (serialno == -1 ? "Unable to connect" : _comment); }
}
public void ReportConnectionError(string errmsg)
Modified: trunk/plugins/VeraControl/DeviceTemperature.cs
===================================================================
--- trunk/plugins/VeraControl/DeviceTemperature.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/DeviceTemperature.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -21,7 +21,7 @@
public string _temperature = "0"; // public thermostat class
private bool _metric = true;
- public DeviceTemperature(XmlNode xn, bool metric) : base (xn)
+ public DeviceTemperature(XmlNode xn, int verabox, bool metric) : base (xn, verabox)
{
_metric = metric;
if (xn != null)
@@ -39,31 +39,23 @@
public override int level
{
get { return int.Parse(_temperature); }
- set { }
}
public override int maxLevel
{
get { return (_metric ? 100 : 212); }
- set { }
}
public override int minLevel
{
get { return (_metric ? -22 : -7); }
- set { }
}
public override string ToString()
{
return name + " [" + GetStatusText() + "]";
}
-
- public override string GetIconName()
- {
- return "Temperature_Sensor";
- }
-
+
public override string GetStatusText()
{
return _temperature + (_metric ? "°C" : "°F");
Modified: trunk/plugins/VeraControl/DeviceThermostat.cs
===================================================================
--- trunk/plugins/VeraControl/DeviceThermostat.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/DeviceThermostat.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -24,7 +24,7 @@
private string _mode = "Off"; // "Off', "InDeadBand", "HeatOn", "CoolOn", "AutoChangeOver", "AuxHeatOn", "EconomyHeatOn", "EmergencyHeatOn",
// "AuxCoolOn", "EconomyCoolOn", "BuildingProtection", "EnergySavingsHeating", "EnergySavingsCooling"
- public DeviceThermostat(XmlNode xn, bool metric) : base (xn, metric)
+ public DeviceThermostat(XmlNode xn, int verabox, bool metric) : base (xn, verabox, metric)
{
_metric = metric;
if (xn != null)
@@ -51,7 +51,6 @@
public override int level
{
get { return -1; }
- set { }
}
public override string mode
@@ -62,11 +61,11 @@
{
ReportPendingRequest();
// Do something with vera
- string cmd = "?id=lu_action&DeviceNum="+id.ToString()+
+ string cmd = "?id=lu_action&DeviceNum=" + internalId.ToString( )+
"&serviceId=urn:upnp-org:serviceId:HVAC_UserOperatingMode1&action=SetModeTarget" +
- "&NewModeTarget="+(value == "Off" ? "Off" : (value == "Cool" ? "CoolOn" : (value == "Heat" ? "HeatOn" : "AutoChangeOver"))
+ "&NewModeTarget=" + (value == "Off" ? "Off" : (value == "Cool" ? "CoolOn" : (value == "Heat" ? "HeatOn" : "AutoChangeOver"))
);
- _vera.DoVeraCommandRequest(cmd, ReportRequestError);
+ _myVeraBox.DoVeraCommandRequest(cmd, ReportRequestError);
}
}
}
@@ -79,13 +78,11 @@
public override bool isControllable
{
get { return true; }
- set { }
}
public override int maxLevel
{
get { return -1; }
- set { }
}
public override string GetStatusText()
@@ -97,12 +94,7 @@
{
return _hvacState + " - Fan : " + _fanMode + " - " + _temperature + (_metric ? "°C" : "°F") ;
}
-
- public override string GetIconName()
- {
- return "Thermostat";
- }
-
+
public override string [] GetCommands()
{
return new string [] {"Off", "On", "Auto", "Heat", "Cool"};
Modified: trunk/plugins/VeraControl/DeviceWindowCovering.cs
===================================================================
--- trunk/plugins/VeraControl/DeviceWindowCovering.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/DeviceWindowCovering.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -18,17 +18,12 @@
/// </summary>
public class DeviceWindowCovering : DeviceDimmer
{
- public DeviceWindowCovering(XmlNode xn) : base (xn)
+ public DeviceWindowCovering(XmlNode xn, int verabox) : base (xn, verabox)
{
if (xn != null)
{
Update(xn);
}
}
-
- public override string GetIconName()
- {
- return "Window_Covering";
- }
}
}
Modified: trunk/plugins/VeraControl/DialogActionTrigger.cs
===================================================================
--- trunk/plugins/VeraControl/DialogActionTrigger.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/DialogActionTrigger.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -116,7 +116,7 @@
base.OnClicked(controlId, control, actionType);
}
- private void InitSpinButtons(GUISpinButton spin, int selectedScene)
+ private void InitSpinButtons(GUISpinButton spin, long selectedScene)
{
GUIControl.ClearControl(GetID, spin.GetID);
int iSceneIndex = 0;
@@ -124,8 +124,8 @@
for (int i = 0; i < _vera.scenes.Count; i++)
{
- spin.AddSpinLabel(shortString(_vera.scenes[i].name), _vera.scenes[i].id);
- if (_vera.scenes[i].id == selectedScene)
+ spin.AddSpinLabel(shortString(_vera.scenes[i].name), i + 1);
+ if (_vera.scenes[i].configChangeProofId == selectedScene)
{
iSceneIndex = i + 1; // 0 is - none -
}
@@ -160,7 +160,7 @@
if (spinList[i].SpinValue == 0) {
_vera.actionTriggerTable[i] = 0;
} else {
- _vera.actionTriggerTable[i] = _vera.scenes[spinList[i].SpinValue - 1].id;
+ _vera.actionTriggerTable[i] = _vera.scenes[spinList[i].SpinValue - 1].configChangeProofId;
}
xmlwritter.SetValue("veracontroller", ((Actiontrigger) i).ToString(), _vera.actionTriggerTable[i].ToString());
}
Modified: trunk/plugins/VeraControl/DialogDeviceControl.cs
===================================================================
--- trunk/plugins/VeraControl/DialogDeviceControl.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/DialogDeviceControl.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -135,26 +135,33 @@
if (_myDev.isControllable)
{
if (_myDev.GetType() == typeof(DeviceSprinkler))
- {
+ { // Special Sprinkler device
SetText(_myDev.name, _myDev.GetStatusText() + " - " + _myDev.mode, _myDev.GetExtraText() );
SetActiveBut((_myDev.status ? 1 : 0), (_myDev.mode == "Auto" ? 0 : (_myDev.mode == "Block" ? 2 : 1) ));
}
else if (_myDev.GetType() == typeof(DeviceThermostat))
- {
+ { // Thermostat device
SetText(_myDev.name, _myDev.GetStatusText(), _myDev.GetExtraText() );
SetActiveBut((_myDev.status ? 1 : 0), (_myDev.mode == "Auto" ? 0 :
(_myDev.mode == "CoolOn" || _myDev.mode == "Cool" ? 1 :
(_myDev.mode == "HeatOn" || _myDev.mode == "Heat" ? 2 : 3) )));
}
+ else if (_myDev.GetType() == typeof(DeviceDimmer))
+ { // Dimmer device
+ SetText(_myDev.name, "Dim level: " + _myDev.GetStatusText(), _myDev.GetExtraText() );
+ SetActiveBut((_myDev.mode == "Off" ? 0 : (_myDev.mode == "On" ? 1 : 2)),
+ (_myDev.mode == "25%" ? 0 : (_myDev.mode == "50%" ? 1 : (_myDev.mode == "75%" ? 2 : 3) )));
+ }
else if (_myDev.GetType() == typeof(DeviceCam))
- {
+ { // WebCam device
SetText(_myDev.name, _myDev.GetStatusText(), _myDev.GetExtraText());
}
else
- {
+ { // Rest of the devices
SetText(_myDev.name, "", "");
SetActiveBut(_myDev.status ? 1 : 0, -1);
}
+
// No slider or status buttons for a cam-device
if (_myDev.GetType() != typeof(DeviceCam))
{
@@ -169,6 +176,7 @@
{
SetText(_myDev.name, _myDev.GetStatusText(), _myDev.GetExtraText());
}
+
// save last update ticks
_lastUpdate = DateTime.Now.Ticks;
}
@@ -316,7 +324,7 @@
public int camUpdateDelay
{
- get { return _camUpdateDelay; }
+ get { return _camUpdateDelay; }
set { _camUpdateDelay = value; }
}
Modified: trunk/plugins/VeraControl/Room.cs
===================================================================
--- trunk/plugins/VeraControl/Room.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/Room.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -4,8 +4,8 @@
* Date: 22-12-2011
* Time: 14:05
*
- * Copyright: 2012 GPL - Bart Eversdijk
- * MediaPort plugin - MicasaVerde (TM) Vera Controller
+ * Copyright: 2012 GPL - Bart Eversdijk
+ * MediaPort plugin - MicasaVerde (TM) Vera Controller
* E-mail: ba...@ev...
*/
using System;
@@ -18,18 +18,19 @@
/// </summary>
public class Room
{
- public Room(XmlNode xn)
+ public Room(XmlNode xn, int veraid)
{
+ _myVeraBox = VeraCommunication.Instance.boxes[veraid];
if (xn != null)
{
Update(xn);
}
}
- public VeraHelper _helper = VeraHelper.Instance;
- public VeraCommunication _vera = VeraCommunication.Instance;
+ public VeraHelper _helper = VeraHelper.Instance;
+ public VeraBox _myVeraBox;
- private string _name = "unknown room";
+ private string _name = "unassigned";
private int _id = 0;
private int _section = 0;
@@ -44,14 +45,15 @@
// void room no further processing needed
return true;
}
+
// Make sure room exists
- if (_section == 0 || !_vera.status.IsSectionFound(_section))
+ if (section == _myVeraBox.zeroId || !_myVeraBox.status.IsSectionFound(section))
{
- if (!_vera.status.IsSectionFound(0))
+ section = _myVeraBox.zeroId;
+ if (!_myVeraBox.status.IsSectionFound(section))
{ // create dummy room to attach to
- _vera.sections.Add(new Section(null));
+ _myVeraBox.sections.Add(new Section(null, _myVeraBox.myId));
}
- _section = 0;
}
return true;
@@ -59,20 +61,38 @@
public int id
{
+ get {
+ if (_myVeraBox == null)
+ {
+ return 0;
+ }
+ return _id + (VeraCommunication.IDMASK * _myVeraBox.myId);
+ }
+ }
+
+ public int internalId
+ {
get { return _id; }
- set { }
}
-
+
public string name
{
- get { return _name; }
- set { }
+ get { return _name; }
}
public int section
{
- get { return _section; }
- set { }
+ get {
+ if (_myVeraBox == null)
+ {
+ return 0;
+ }
+ return _section + (VeraCommunication.IDMASK * _myVeraBox.myId);
+ }
+ set
+ {
+ _section = (value % VeraCommunication.IDMASK);
+ }
}
public override string ToString()
Modified: trunk/plugins/VeraControl/Scene.cs
===================================================================
--- trunk/plugins/VeraControl/Scene.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/Scene.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -19,8 +19,9 @@
/// </summary>
public class Scene : BaseDevice
{
- public Scene(XmlNode xn) : base (xn)
+ public Scene(XmlNode xn, int verabox) : base (xn, verabox)
{
+ _myVeraBox = VeraCommunication.Instance.boxes[verabox];
if (xn != null)
{
Update(xn);
@@ -32,14 +33,7 @@
public override bool Update(XmlNode xn)
{
_active = _helper.GetAttrAsBool(xn, "active", _active);
- bool b = base.Update(xn);
-
- // Make sure the room exists or else make it 0
- if (room != 0 && !_vera.status.IsRoomFound(room))
- {
- room = 0;
- }
- return b;
+ return base.Update(xn);
}
public override string GetIconName()
@@ -49,7 +43,7 @@
public override string GetStatusText()
{
- return (room == 0 ? "" : _vera.status.GetRoomById(room).name);
+ return (room == _myVeraBox.zeroId ? "" : _myVeraBox.status.GetRoomById(room).name);
}
public bool IsActive()
@@ -61,13 +55,13 @@
{
if (id == 0)
{
- _vera.status.system.ReportCommandError("Unknown scene");
+ _myVeraBox.status.system.ReportCommandError("Unknown scene");
screenUpdateRequired = true;
return;
}
ReportPendingRequest();
string cmd = "?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="+id;
- _vera.DoVeraCommandRequest(cmd, ReportRequestError);
+ _myVeraBox.DoVeraCommandRequest(cmd, ReportRequestError);
}
}
}
Modified: trunk/plugins/VeraControl/Section.cs
===================================================================
--- trunk/plugins/VeraControl/Section.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/Section.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -4,8 +4,8 @@
* Date: 23-12-2011
* Time: 21:05
*
- * Copyright: 2012 GPL - Bart Eversdijk
- * MediaPort plugin - MicasaVerde (TM) Vera Controller
+ * Copyright: 2012 GPL - Bart Eversdijk
+ * MediaPort plugin - MicasaVerde (TM) Vera Controller
* E-mail: ba...@ev...
*/
using System;
@@ -18,8 +18,9 @@
/// </summary>
public class Section
{
- public Section(XmlNode xn)
+ public Section(XmlNode xn, int verabox)
{
+ _myVeraBox = VeraCommunication.Instance.boxes[verabox];
if (xn != null)
{
Update(xn);
@@ -28,8 +29,9 @@
public VeraHelper _helper = VeraHelper.Instance;
- private string _name = "unknown section";
- private int _id = 0;
+ private string _name = "";
+ private int _id = 0;
+ public VeraBox _myVeraBox = null;
public bool Update(XmlNode xn)
{
@@ -40,16 +42,44 @@
public int id
{
+ get {
+ if (_myVeraBox == null)
+ {
+ return 0;
+ }
+ return (VeraCommunication.IDMASK * _myVeraBox.myId) + _id;
+ }
+ }
+
+ public int _internalId
+ {
get { return _id; }
- set { }
}
-
+
public string name
{
- get { return _name; }
- set { }
+ get
+ {
+ if (_myVeraBox == null)
+ {
+ return (_name == "" ? "unknown section" : _name);
+ }
+ return (_name == "" ? _myVeraBox.name : _name);
+ }
}
+ public string longName
+ {
+ get
+ {
+ if (_myVeraBox == null)
+ {
+ return _name;
+ }
+ return ((_myVeraBox.name != "" && _myVeraBox.name != "-") ? _myVeraBox.name + " : " : "") + _name;
+ }
+ }
+
public override string ToString()
{
return name;
Modified: trunk/plugins/VeraControl/VeraCommunication.cs
===================================================================
--- trunk/plugins/VeraControl/VeraCommunication.cs 2012-02-17 15:42:33 UTC (rev 4455)
+++ trunk/plugins/VeraControl/VeraCommunication.cs 2012-02-17 23:12:46 UTC (rev 4456)
@@ -17,684 +17,575 @@
namespace VeraControl.Properties
{
+ public enum VeraSortStyle
+ {
+ NO = 0,
+ ROOMS_ONLY_ASORT,
+ ROOMS_ONLY_DSORT,
+ GROUP_BOXES_ASORT,
+ GROUP_BOXES_DSORT,
+
+ LAST
+ };
+
+ public class SortItem
+ {
+ public SortItem(VeraSortStyle sort, string t, string s)
+ {
+ option = sort;
+ fulltext = t;
+ shorttext = s;
+ }
+ public VeraSortStyle option;
+ public string fulltext;
+ public string shorttext;
+ }
+
+ public enum VeraFilterStyle
+ {
+ NONE = 0,
+ UNKNOWN_DEVICES,
+ GENERIC_DEVICES,
+ REMOTE_DEVICES,
+ SCENE_CONTROLLERS,
+ CONTROLABLE_ONLY,
+
+ LAST
+ };
+
+ public class FilterItem
+ {
+ public FilterItem(VeraFilterStyle f, string t, string s)
+ {
+ option = f;
+ fulltext = t;
+ shorttext = s;
+ }
+ public VeraFilterStyle option;
+ public string fulltext;
+ public string shorttext;
+ }
+
+
/// <summary>
/// Description of VeraCommunication.
/// </summary>
- public class VeraStatus
+ public sealed class VeraCommunication
{
- public DeviceSystem system = new DeviceSystem();
- public List<DeviceGeneric> devices = new List<DeviceGeneric>();
- public List<Scene> scenes = new List<Scene>();
- public List<Room> rooms = new List<Room>();
- public List<DevCategories> categories = new List<DevCategories>();
- public List<Section> sections = new List<Section>();
+ private static volatile VeraCommunication _instance;
+ private static object _syncRoot = new Object();
+ private VeraHelper _helper = VeraHelper.Instance;
- #region Vers get by id support functions
-
- public void ClearAllLists()
+ // Config data
+ private int _numOfBoxes = 1;
+ public VeraBox [] boxes;
+
+ public const int IDMASK = 0xFFFF;
+ public const int ALL = Int32.MaxValue;
+
+ // Action control table
+ public long [] actionTriggerTable = new long[(int)Actiontrigger.LAST_ACTIONTRIGGER];
+
+ public static VeraCommunication Instance
{
- devices.Clear();
- scenes.Clear();
- rooms.Clear();
- categories.Clear();
- sections.Clear();
- }
- public Room GetRoomById(int id)
- {
- foreach(Room room in rooms)
+ get
{
- if (room.id == id)
+ if (_instance == null)
{
- return room;
+ lock (_syncRoot)
+ {
+ if (_instance == null)
+ {
+ _instance = new VeraCommunication();
+
+ using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.MPSettings())
+ {
+ int maxRefreshDelay = xmlreader.GetValueAsInt("veracontroller", "maxrefreshdelay", 60);
+ _instance._numOfBoxes = xmlreader.GetValueAsInt("veracontroller", "NumOfBoxes", -1);
+ bool oldStyleConfig = (_instance._numOfBoxes == -1);
+ if (oldStyleConfig)
+ {
+ _instance._numOfBoxes = 1;
+ _instance.boxes = new VeraBox[1];
+ _instance.boxes[0] = new VeraBox(0, maxRefreshDelay, 1000);
+ _instance.boxes[0]._oldStyleConfig = true;
+ }
+ else
+ {
+ _instance.boxes = new VeraBox[_instance._numOfBoxes];
+ for (int i = 0; i < _instance._numOfBoxes; i++)
+ {
+ _instance.boxes[i] = new VeraBox(i, maxRefreshDelay, 1000);
+ }
+ }
+
+ for (Actiontrigger i = 0; i < Actiontrigger.LAST_ACTIONTRIGGER; i++)
+ {
+ _instance.actionTriggerTable[(int)i] = long.Parse(xmlreader.GetValueAsString("veracontroller", i.ToString(), "0"));
+ }
+ }
+ }
+ }
}
+
+ return _instance;
}
- return new Room(null);
}
- public Section GetSectionById(int id)
+ private VeraCommunication()
{
- foreach(Section section in sections)
- {
- if (section.id == id)
- {
- return section;
- }
- }
- return new Section(null);
}
- public DeviceGeneric GetDeviceById(int id)
+ public bool IsVeraAlive(string ip, string port)
{
- foreach(DeviceGeneric dev in devices)
- {
- if (dev.id == id)
- {
- return dev;
- }
- }
- return new DeviceGeneric(null);
+ string response = RetrieveURL("http://" + ip + ":" + port + "/data_request?id=lu_alive&time=" + DateTime.Now.Ticks);
+ return (response == "OK");
}
- public Scene GetSceneById(int id)
+ private string RetrieveURL(string url)
{
- foreach(Scene scene in scenes)
+ // No callback thus Synchronised call (wait for response)
+ try {
+ WebClient wc = new WebClient();
+ wc.CancelAsync(); // Cancel any current pending Async calls...
+ return wc.DownloadString(url);
+ } catch( Exception )
{
- if (scene.id == id)
- {
- return scene;
- }
+ return "ERROR";
}
- return new Scene(null);
}
- public DevCategories GetCategoryById(int id)
+ public int numOfBoxes
{
- foreach(DevCategories cat in categories)
- {
- if (cat.id == id)
- {
- return cat;
- }
- }
- return new DevCategories(null);
+ get { return _numOfBoxes; }
}
- public bool IsSectionFound(int id)
+ public int BoxId(long id)
{
- foreach(Section section in sections)
- {
- if (section.id == id)
- {
- return true;
- }
- }
- return false;
+ return (int)(id / IDMASK);
}
- public bool IsRoomFound(int id)
+ public int DeviceId(long id)
{
- foreach(Room room in rooms)
+ return (int)(id % IDMASK);
+ }
+
+ public void UpdateStatusOfAllBoxes()
+ {
+ for (int i = 0; i < numOfBoxes; i++)
{
- if (room.id == id)
- {
- return true;
- }
+ boxes[i].UpdateCurrentStatus();
}
- return false;
}
- public bool IsDeviceFound(int id)
+ public bool IsABoxPendingUnpdate()
{
- foreach(DeviceGeneric dev in devices)
+ for (int i = 0; i < numOfBoxes; i++)
{
- if (dev.id == id)
+ if (boxes[i].updatePending)
{
return true;
}
}
return false;
}
+
+ public Room GetRoomById(int id)
+ {
+ return boxes[BoxId(id)].status.GetRoomById(id);
+ }
+
+ public Section GetSectionById(int id)
+ {
+ return boxes[BoxId(id)].status.GetSectionById(id);
+ }
+
+ public DeviceGeneric GetDeviceById(int id)
+ {
+ return boxes[BoxId(id)].status.GetDeviceById(id);
+ }
- public bool IsSceneFound(int id)
+ public Scene GetSceneById(int id)
{
- foreach(Scene scene in scenes)
+ return boxes[BoxId(id)].status.GetSceneById(id);
+ }
+
+ public Scene GetSceneByConfigProofId(long id)
+ {
+ for (int i = 0; i < numOfBoxes; i++)
{
- if (scene.id == id)
+ if (boxes[i].status.system.serialno == BoxId(id))
{
- return true;
+ return boxes[i].status.GetSceneById(boxes[i].makeId((int)(id % IDMASK))) ;
}
}
- return false;
+ return new Scene(null, 0);
}
- public bool IsCategoryFound(int id)
+ public DevCategorie...
[truncated message content] |