예제 #1
0
파일: Program.cs 프로젝트: garronej/Domotic
        void presenceSensor_SomeoneDetected(PresenceSensor sender, bool presence)
        {
            Debug.Print("Presence : " + (presence ? "yes" : "no"));
            InfoToHost info = new InfoToHost();

            info.DataType = "presence";
            info.Value    = presence?1.0:0.0;
            queue.push(info);
            status.Presence = presence;
#if DEBUG
            Debug.Print("Presence : " + (presence ? "yes" : "no"));
#endif
        }
        public void PresenceSensor_FromDynamic_ShouldReturnExpectedResult(InstalledAppInstance installedApp)
        {
            var expectedResult = new PresenceSensor()
            {
                Id           = Guid.NewGuid().ToString(),
                Label        = "MyDevice",
                CurrentState = PresenceState.NotPresent
            };

            var deviceJson = $@"{{
                ""deviceId"": ""{expectedResult.Id}"",
                ""name"": ""NAME"",
                ""label"": ""{expectedResult.Label}"",
                ""locationId"": ""{installedApp.InstalledLocation.Id}""
            }}";

            var statusJson = $@"{{
                ""deviceId"": ""{expectedResult.Id}"",
                ""name"": ""NAME"",
                ""label"": ""{expectedResult.Label}"",
                ""locationId"": ""{installedApp.InstalledLocation.Id}"",
                ""components"" : {{
                    ""main"": {{
                        ""presenceSensor"": {{
                            ""presence"": {{
                                ""value"": ""not present""
                            }}
                        }}
                    }}
                }}
            }}";

            dynamic device = JObject.Parse(deviceJson);
            dynamic status = JObject.Parse(statusJson);

            var result = PresenceSensor.PresenceSensorFromDynamic(device,
                                                                  status);

            Assert.Equal(expectedResult, result);

            expectedResult.CurrentState = PresenceState.Present;
            statusJson = $@"{{
                ""deviceId"": ""{expectedResult.Id}"",
                ""name"": ""NAME"",
                ""label"": ""{expectedResult.Label}"",
                ""locationId"": ""{installedApp.InstalledLocation.Id}"",
                ""components"" : {{
                    ""main"": {{
                        ""presenceSensor"": {{
                            ""presence"": {{
                                ""value"": ""present""
                            }}
                        }}
                    }}
                }}
            }}";

            status = JObject.Parse(statusJson);

            result = PresenceSensor.PresenceSensorFromDynamic(device,
                                                              status);

            Assert.Equal(expectedResult, result);

            expectedResult.CurrentState = PresenceState.Unknown;
            statusJson = $@"{{
                ""deviceId"": ""{expectedResult.Id}"",
                ""name"": ""NAME"",
                ""label"": ""{expectedResult.Label}"",
                ""locationId"": ""{installedApp.InstalledLocation.Id}"",
                ""components"" : {{
                    ""main"": {{
                        ""presenceSensor"": {{
                            ""presence"": {{
                                ""value"": ""unknown""
                            }}
                        }}
                    }}
                }}
            }}";

            status = JObject.Parse(statusJson);

            result = PresenceSensor.PresenceSensorFromDynamic(device,
                                                              status);

            Assert.Equal(expectedResult, result);

            _ = expectedResult.GetHashCode();
            _ = expectedResult.ToJson();
        }
예제 #3
0
        public static OperationMessage RefreshState(this PresenceSensor presence)
        {
            ushort destinationAddress = (ushort)(presence.Connector == null ? 0 : presence.Connector.Node.Address);

            return(OperationMessage.PresenceRead((ushort)presence.Id, destinationAddress));
        }