Blame domoticz-ozw-barrier-support-0001.patch

8d07018
From a325940d059dd564a16b424cf1020aac6d10f69e Mon Sep 17 00:00:00 2001
8d07018
From: jowerg <jowerg@gmail.com>
8d07018
Date: Sat, 22 Apr 2017 08:44:08 -0400
8d07018
Subject: [PATCH] Initial support for devices using
8d07018
 COMMAND_CLASS_BARRIER_OPERATOR. Tested using Linear GD00Z-4
8d07018
8d07018
---
8d07018
 README.md                                          |  5 ++
8d07018
 hardware/OpenZWave.cpp                             | 54 +++++++++++++++++++++-
8d07018
 hardware/ZWaveCommands.h                           |  1 +
8d07018
 hardware/openzwave/command_classes/Alarm.h         |  2 +-
8d07018
 hardware/openzwave/command_classes/CentralScene.h  | 46 +++++++++---------
8d07018
 .../openzwave/command_classes/SceneActivation.h    |  1 +
8d07018
 hardware/openzwave/control_panel/zwavelib.cpp      |  2 +
8d07018
 7 files changed, 85 insertions(+), 26 deletions(-)
8d07018
8d07018
diff --git a/README.md b/README.md
8d07018
index 8ee56fecd..4e7ef9f02 100644
8d07018
--- a/README.md
8d07018
+++ b/README.md
8d07018
@@ -2,6 +2,11 @@
8d07018
 
8d07018
 Domoticz is a Home Automation System that lets you monitor and configure various devices like: Lights, Switches, various sensors/meters like Temperature, Rain, Wind, UV, Electra, Gas, Water and much more. Notifications/Alerts can be sent to any mobile device
8d07018
 
8d07018
+## OpenZWave Library - BARRIER OPERATOR support
8d07018
+You will need to apply the patch implemented by @srirams as described on:
8d07018
+https://github.com/OpenZWave/open-zwave/issues/490
8d07018
+
8d07018
+
8d07018
 ## Multi platform: Linux/Windows/Embedded Devices
8d07018
 
8d07018
 This system is designed to operate in various operating systems.
8d07018
diff --git a/hardware/OpenZWave.cpp b/hardware/OpenZWave.cpp
8d07018
index 186d51134..4c046d806 100644
8d07018
--- a/hardware/OpenZWave.cpp
8d07018
+++ b/hardware/OpenZWave.cpp
8d07018
@@ -250,10 +250,12 @@ const char *cclassStr(uint8 cc)
8d07018
 		return "MULTI INSTANCE";
8d07018
 	case 0x62:
8d07018
 		return "DOOR LOCK";
8d07018
 	case 0x63:
8d07018
 		return "USER CODE";
8d07018
+	case 0x66:
8d07018
+		return "BARRIER OPERATOR";
8d07018
 	case 0x70:
8d07018
 		return "CONFIGURATION";
8d07018
 	case 0x71:
8d07018
 		return "ALARM";
8d07018
 	case 0x72:
8d07018
@@ -1229,27 +1231,47 @@ bool COpenZWave::SwitchLight(const int nodeID, const int instanceID, const int c
8d07018
 		bool bFound = (GetValueByCommandClass(nodeID, instanceID, COMMAND_CLASS_SWITCH_BINARY, vID) == true);
8d07018
 		if (!bFound)
8d07018
 			bFound = (GetValueByCommandClass(nodeID, instanceID, COMMAND_CLASS_DOOR_LOCK, vID) == true);
8d07018
 		if (!bFound)
8d07018
 			bFound = (GetValueByCommandClassLabel(nodeID, instanceID, COMMAND_CLASS_SWITCH_MULTILEVEL, "Level", vID) == true);
8d07018
+		if (!bFound)
8d07018
+			bFound = (GetValueByCommandClass(nodeID, instanceID, COMMAND_CLASS_BARRIER, vID) == true);
8d07018
 		if (bFound)
8d07018
 		{
8d07018
-			OpenZWave::ValueID::ValueType vType = vID.GetType();
8d07018
-			_log.Log(LOG_NORM, "OpenZWave: Domoticz has send a Switch command! NodeID: %d (0x%02x)", nodeID, nodeID);
8d07018
-			if (vType == OpenZWave::ValueID::ValueType_Bool)
8d07018
-			{
8d07018
-				if (svalue == 0) {
8d07018
-					//Off
8d07018
-					m_pManager->SetValue(vID, false);
8d07018
-					pDevice->intvalue = 0;
8d07018
-				}
8d07018
-				else {
8d07018
-					//On
8d07018
-					m_pManager->SetValue(vID, true);
8d07018
-					pDevice->intvalue = 255;
8d07018
-				}
8d07018
-			}
8d07018
+            OpenZWave::ValueID::ValueType vType = vID.GetType();
8d07018
+            _log.Log(LOG_NORM, "OpenZWave: Domoticz has send a Switch command! NodeID: %d (0x%02x)", nodeID, nodeID);
8d07018
+            if (vType == OpenZWave::ValueID::ValueType_Bool)
8d07018
+            {
8d07018
+                if (svalue == 0) {
8d07018
+                    //Off
8d07018
+            _log.Log(LOG_NORM, "OpenZWave: Domoticz has send an OFF Switch command! NodeID: %d (FALSE) Command: 0x%02x", nodeID,commandClass);
8d07018
+                    m_pManager->SetValue(vID, false);
8d07018
+                        pDevice->intvalue = 0;
8d07018
+                }
8d07018
+                else {
8d07018
+                    //On
8d07018
+            _log.Log(LOG_NORM, "OpenZWave: Domoticz has send an ON Switch command! NodeID: %d (TRUE)  Command: 0x%02x", nodeID, commandClass);
8d07018
+                    m_pManager->SetValue(vID, true);
8d07018
+                        pDevice->intvalue = 255;
8d07018
+                }
8d07018
+            }
8d07018
+            else if (vType == OpenZWave::ValueID::ValueType_List)
8d07018
+            {
8d07018
+                std::string BarrierOpen = "Open";
8d07018
+                std::string BarrierClose = "Close";
8d07018
+
8d07018
+                if (svalue == 0) {
8d07018
+                    //Off
8d07018
+                    _log.Log(LOG_NORM, "OpenZWave: Domoticz has send an OFF Switch command! NodeID: %d (Closed)  Command: 0x%02x", nodeID, commandClass);
8d07018
+                    m_pManager->SetValueListSelection(vID, BarrierClose);
8d07018
+                }
8d07018
+                else {
8d07018
+                    //On
8d07018
+                    _log.Log(LOG_NORM, "OpenZWave: Domoticz has send an ON Switch command! NodeID: %d (Open)  Command: 0x%02x", nodeID, commandClass);
8d07018
+                    m_pManager->SetValueListSelection(vID, BarrierOpen);
8d07018
+                }
8d07018
+            }
8d07018
 			else
8d07018
 			{
8d07018
 				if (svalue == 0) {
8d07018
 					//Off
8d07018
 					m_pManager->SetValue(vID, 0);
8d07018
@@ -2216,10 +2238,39 @@ void COpenZWave::AddValue(const OpenZWave::ValueID &vID, const NodeInfo *pNodeIn
8d07018
 				else
8d07018
 					_device.intvalue = 0;
8d07018
 				InsertDevice(_device);
8d07018
 			}
8d07018
 		}
8d07018
+	}
8d07018
+	else if (commandclass == COMMAND_CLASS_BARRIER) 
8d07018
+	{
8d07018
+
8d07018
+                if (vLabel == "Open" ) 
8d07018
+                {
8d07018
+			// We are going to define a Domoticz Control for the Garage opener
8d07018
+			_device.devType = ZDTYPE_SWITCH_NORMAL;
8d07018
+
8d07018
+
8d07018
+                        if (m_pManager->GetValueAsBool(vID, &bValue) == true)
8d07018
+                        {
8d07018
+                                if (bValue == true)
8d07018
+                                        _device.intvalue = 255;
8d07018
+                                else
8d07018
+                                        _device.intvalue = 0;
8d07018
+                        }
8d07018
+                        else if (m_pManager->GetValueAsByte(vID, &byteValue) == true)
8d07018
+                        {
8d07018
+                                if (byteValue == 0)
8d07018
+                                        _device.intvalue = 0;
8d07018
+                                else
8d07018
+                                        _device.intvalue = 255;
8d07018
+                        }
8d07018
+                        InsertDevice(_device);
8d07018
+
8d07018
+                }
8d07018
+
8d07018
+
8d07018
 	}
8d07018
 	else
8d07018
 	{
8d07018
 		//Unhandled
8d07018
 		_log.Log(LOG_STATUS, "OpenZWave: Unhandled class: 0x%02X (%s), NodeID: %d (0x%02x), Index: %d, Instance: %d", commandclass, cclassStr(commandclass), NodeID, NodeID, vOrgIndex, vOrgInstance);
8d07018
@@ -2746,10 +2797,23 @@ void COpenZWave::UpdateValue(const OpenZWave::ValueID &vID)
8d07018
 				intValue = 0;
8d07018
 			else
8d07018
 				intValue = 255;
8d07018
 			pDevice->intvalue = intValue;
8d07018
 		}
8d07018
+		else if (commandclass == COMMAND_CLASS_BARRIER)
8d07018
+		{
8d07018
+			if (vLabel == "Barrier State Numeric")
8d07018
+			{
8d07018
+				int intValue = 0;
8d07018
+				if (byteValue == 0)
8d07018
+					intValue = 0;
8d07018
+				else
8d07018
+					intValue = 255;
8d07018
+				pDevice->intvalue = intValue;
8d07018
+				_log.Log(LOG_STATUS, "GetValue BARRIER CLASS byteValue: %d , Node (0x%02x) , Label: %s", byteValue, NodeID, vLabel.c_str());
8d07018
+			} 
8d07018
+		}
8d07018
 		else if (commandclass == COMMAND_CLASS_ALARM)
8d07018
 		{
8d07018
 			/*
8d07018
 			_log.Log(LOG_STATUS, "------------------------------------");
8d07018
 			_log.Log(LOG_STATUS, "Label: %s", vLabel.c_str());
8d07018
diff --git a/hardware/ZWaveCommands.h b/hardware/ZWaveCommands.h
8d07018
index 9e80713de..0daf0db31 100644
8d07018
--- a/hardware/ZWaveCommands.h
8d07018
+++ b/hardware/ZWaveCommands.h
8d07018
@@ -51,6 +51,7 @@
8d07018
 #define COMMAND_CLASS_MULTI_INSTANCE			0x60
8d07018
 #define COMMAND_CLASS_DOOR_LOCK					0x62
8d07018
 #define COMMAND_CLASS_USER_CODE					0x63
8d07018
+#define COMMAND_CLASS_BARRIER					0x66
8d07018
 
8d07018
 #define COMMAND_CLASS_CONFIGURATION				0x70
8d07018
 #define COMMAND_CLASS_ALARM						0x71
8d07018
diff --git a/hardware/openzwave/command_classes/Alarm.h b/hardware/openzwave/command_classes/Alarm.h
8d07018
index 528fd022d..9cbdd6bd4 100644
8d07018
--- a/hardware/openzwave/command_classes/Alarm.h
8d07018
+++ b/hardware/openzwave/command_classes/Alarm.h
8d07018
@@ -56,7 +56,7 @@ namespace OpenZWave
8d07018
 		virtual string const GetCommandClassName()const{ return StaticGetCommandClassName(); }
8d07018
 		/** \brief Handle a response to a message associated with this command class. (Inherited from CommandClass) */
8d07018
 		virtual bool HandleMsg( uint8 const* _data, uint32 const _length, uint32 const _instance = 1 );
8d07018
-
8d07018
+		virtual bool SetValue( Value const& _value );
8d07018
 		virtual uint8 GetMaxVersion(){ return 3; }
8d07018
 
8d07018
 	protected:
8d07018
diff --git a/hardware/openzwave/command_classes/CentralScene.h b/hardware/openzwave/command_classes/CentralScene.h
8d07018
index f9a34fd22..0a869c438 100644
8d07018
--- a/hardware/openzwave/command_classes/CentralScene.h
8d07018
+++ b/hardware/openzwave/command_classes/CentralScene.h
8d07018
@@ -35,45 +35,45 @@ namespace OpenZWave
8d07018
 	class ValueByte;
8d07018
 
8d07018
 	/** \brief Implements COMMAND_CLASS_CENTRAL_SCENE (0x5B), a Z-Wave device command class.
8d07018
-	*/
8d07018
-	class CentralScene : public CommandClass
8d07018
+	 */
8d07018
+	class CentralScene: public CommandClass
8d07018
 	{
8d07018
 	public:
8d07018
-		static CommandClass* Create(uint32 const _homeId, uint8 const _nodeId) { return new CentralScene(_homeId, _nodeId); }
8d07018
-		virtual ~CentralScene() {}
8d07018
+		static CommandClass* Create( uint32 const _homeId, uint8 const _nodeId ){ return new CentralScene( _homeId, _nodeId ); }
8d07018
+		virtual ~CentralScene(){}
8d07018
 
8d07018
 		/** \brief Get command class ID (1 byte) identifying this command class. */
8d07018
-		static uint8 const StaticGetCommandClassId() { return 0x5B; }
8d07018
+		static uint8 const StaticGetCommandClassId(){ return 0x5B; }
8d07018
 		/** \brief Get a string containing the name of this command class. */
8d07018
-		static string const StaticGetCommandClassName() { return "COMMAND_CLASS_CENTRAL_SCENE"; }
8d07018
+		static string const StaticGetCommandClassName(){ return "COMMAND_CLASS_CENTRAL_SCENE"; }
8d07018
 
8d07018
 		// From CommandClass
8d07018
 		/** \brief Get command class ID (1 byte) identifying this command class. (Inherited from CommandClass) */
8d07018
-		virtual uint8 const GetCommandClassId()const { return StaticGetCommandClassId(); }
8d07018
+		virtual uint8 const GetCommandClassId()const{ return StaticGetCommandClassId(); }
8d07018
 		/** \brief Get a string containing the name of this command class. (Inherited from CommandClass) */
8d07018
-		virtual string const GetCommandClassName()const { return StaticGetCommandClassName(); }
8d07018
-		virtual uint8 GetMaxVersion() { return 3; }
8d07018
+		virtual string const GetCommandClassName()const{ return StaticGetCommandClassName(); }
8d07018
+		virtual uint8 GetMaxVersion(){ return 3; }
8d07018
 		/** \brief Handle a response to a message associated with this command class. (Inherited from CommandClass) */
8d07018
-		virtual bool HandleMsg(uint8 const* _data, uint32 const _length, uint32 const _instance = 1);
8d07018
+		virtual bool HandleMsg( uint8 const* _data, uint32 const _length, uint32 const _instance = 1 );
8d07018
 		/** \brief Create Default Vars for this CC */
8d07018
-		void CreateVars(uint8 const _instance);
8d07018
+		void CreateVars( uint8 const _instance );
8d07018
 		/**
8d07018
-		* Creates the ValueIDs for the keyAttributes
8d07018
-		* @param identical
8d07018
-		* @param keyAttributes
8d07018
-		* @param sceneNumber
8d07018
-		* @return
8d07018
-		*/
8d07018
+		 * Creates the ValueIDs for the keyAttributes
8d07018
+		 * @param identical
8d07018
+		 * @param keyAttributes
8d07018
+		 * @param sceneNumber
8d07018
+		 * @return
8d07018
+		 */
8d07018
 		void createSupportedKeyAttributesValues(uint8 keyAttributes, uint8 sceneNumber, uint8 index, uint8 instance);
8d07018
-		void ReadXML(TiXmlElement const* _ccElement);
8d07018
-		void WriteXML(TiXmlElement* _ccElement);
8d07018
-		bool RequestState(uint32 const _requestFlags, uint8 const _instance, Driver::MsgQueue const _queue);
8d07018
-		bool RequestValue(uint32 const _requestFlags, uint8 const _what, uint8 const _instance, Driver::MsgQueue const _queue);
8d07018
+		void ReadXML( TiXmlElement const* _ccElement	);
8d07018
+		void WriteXML( TiXmlElement* _ccElement );
8d07018
+		bool RequestState( uint32 const _requestFlags, uint8 const _instance, Driver::MsgQueue const _queue );
8d07018
+		bool RequestValue( uint32 const _requestFlags, uint8 const _what, uint8 const _instance, Driver::MsgQueue const _queue );
8d07018
 	private:
8d07018
-		CentralScene(uint32 const _homeId, uint8 const _nodeId);
8d07018
+		CentralScene( uint32 const _homeId, uint8 const _nodeId );
8d07018
 		int32 m_scenecount;
8d07018
 	};
8d07018
 
8d07018
 } // namespace OpenZWave
8d07018
 
8d07018
-#endif
8d07018
\ No newline at end of file
8d07018
+#endif
8d07018
diff --git a/hardware/openzwave/command_classes/SceneActivation.h b/hardware/openzwave/command_classes/SceneActivation.h
8d07018
index b2a73716f..cb4a30682 100644
8d07018
--- a/hardware/openzwave/command_classes/SceneActivation.h
8d07018
+++ b/hardware/openzwave/command_classes/SceneActivation.h
8d07018
@@ -54,6 +54,7 @@ namespace OpenZWave
8d07018
 		virtual string const GetCommandClassName()const{ return StaticGetCommandClassName(); }
8d07018
 		/** \brief Handle a response to a message associated with this command class. (Inherited from CommandClass) */
8d07018
 		virtual bool HandleMsg( uint8 const* _data, uint32 const _length, uint32 const _instance = 1 );
8d07018
+		void CreateVars( uint8 const _instance );
8d07018
 
8d07018
 	private:
8d07018
 		SceneActivation( uint32 const _homeId, uint8 const _nodeId ): CommandClass( _homeId, _nodeId ){}
8d07018
diff --git a/hardware/openzwave/control_panel/zwavelib.cpp b/hardware/openzwave/control_panel/zwavelib.cpp
8d07018
index f6659d2e8..82debb7aa 100644
8d07018
--- a/hardware/openzwave/control_panel/zwavelib.cpp
8d07018
+++ b/hardware/openzwave/control_panel/zwavelib.cpp
8d07018
@@ -219,6 +219,8 @@ uint8 cclassNum(char const *str)
8d07018
 		return 0x62;
8d07018
 	else if (strcmp(str, "USER CODE") == 0)
8d07018
 		return 0x63;
8d07018
+	else if (strcmp(str, "BARRIER OPERATOR") == 0)
8d07018
+		return 0x66;
8d07018
 	else if (strcmp(str, "CONFIGURATION") == 0)
8d07018
 		return 0x70;
8d07018
 	else if (strcmp(str, "ALARM") == 0)