Blob Blame History Raw
From a325940d059dd564a16b424cf1020aac6d10f69e Mon Sep 17 00:00:00 2001
From: jowerg <jowerg@gmail.com>
Date: Sat, 22 Apr 2017 08:44:08 -0400
Subject: [PATCH] Initial support for devices using
 COMMAND_CLASS_BARRIER_OPERATOR. Tested using Linear GD00Z-4

---
 README.md                                          |  5 ++
 hardware/OpenZWave.cpp                             | 54 +++++++++++++++++++++-
 hardware/ZWaveCommands.h                           |  1 +
 hardware/openzwave/command_classes/Alarm.h         |  2 +-
 hardware/openzwave/command_classes/CentralScene.h  | 46 +++++++++---------
 .../openzwave/command_classes/SceneActivation.h    |  1 +
 hardware/openzwave/control_panel/zwavelib.cpp      |  2 +
 7 files changed, 85 insertions(+), 26 deletions(-)

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