public async Task UpdateAsync(SensorAlarm alarm) { var table = _client.GetTableClient(_tableName); await table.CreateIfNotExistsAsync(); await table.UpsertEntityAsync(SensorAlarmMapper.Map(alarm)); }
public async Task DeleteAsync(SensorAlarm alarm) { var table = _client.GetTableClient(_tableName); await table.CreateIfNotExistsAsync(); await table.DeleteEntityAsync(alarm.SensorBoxId, alarm.Identifier); }
public static TableEntity Map(SensorAlarm alarm) { return new TableEntity(alarm.SensorBoxId, alarm.Identifier) { [nameof(SensorAlarm.SensorType)] = alarm.SensorType.ToString("G"), [nameof(SensorAlarm.Status)] = alarm.Status.ToString("G"), Timestamp = alarm.FiredAt }; }
protected virtual void Initialize(ISensorManager i_Parent) { if (i_Parent == null) { return; } Samples = new SampleList(this); TimeStamps = new SampleList(this); Alarm = new SensorAlarm(this); InitializeParent(i_Parent); InitializeCalibration(); Samples.OnSampleAdded += ParentSensorManager.SampleAdded; TimeStamps.OnSampleAdded += ParentSensorManager.TimeStampAdded; }
private async Task CreateSensorAlarm(Sensor sensor, AlarmStatus alarmStatus, bool singleton = false) { if (singleton) { var existingAlarm = await _sensorAlarmRepository.GetBySensorBoxIdAndSensorTypeAndStatusAsync(sensor.BoxId, sensor.Type, alarmStatus); if (existingAlarm != null) { return; } } var sensorAlarm = new SensorAlarm { SensorBoxId = sensor.BoxId, SensorType = sensor.Type, Status = alarmStatus }; await _sensorAlarmRepository.InsertAsync(sensorAlarm); }
public async Task CheckObsoleteAlarmsTest() { var sensorRepository = A.Fake <ISensorRepository>(); A.CallTo(() => sensorRepository.GetAllAsync()).Returns(new[] { new Sensor("test", SensorType.Temperature) { Min = 5, Max = 10, LastSeen = DateTimeOffset.UtcNow } }); var sensorAlarmRepository = A.Fake <ISensorAlarmRepository>(); var alarm = new SensorAlarm { SensorBoxId = "test", SensorType = SensorType.Temperature, Status = AlarmStatus.Dead }; A.CallTo(() => sensorAlarmRepository.GetBySensorBoxIdAndSensorTypeAndStatusAsync("test", SensorType.Temperature, AlarmStatus.Dead)).Returns(alarm); var service = new SensorValidationService(sensorRepository, sensorAlarmRepository, A.Fake <ILogger <SensorValidationService> >()); await service.CheckSensorsAndAlarmsAsync(); A.CallTo(() => sensorAlarmRepository.DeleteAsync(alarm)).MustHaveHappened(); }
public virtual bool MessageRequestHandler(byte[] receivedMessage) { //Console.WriteLine("\n _z_ [" + this.NodeId + "] " + (this.DeviceHandler != null ? this.DeviceHandler.ToString() : "!" + this.GenericClass.ToString())); //Console.WriteLine(" >>> " + zp.ByteArrayToString(receivedMessage) + "\n"); ZWaveEvent messageEvent = null; int messageLength = receivedMessage.Length; if (messageLength > 8) { //byte commandLength = receivedMessage[6]; byte commandClass = receivedMessage[7]; switch (commandClass) { case (byte)CommandClass.Basic: messageEvent = Basic.GetEvent(this, receivedMessage); break; case (byte)CommandClass.Alarm: messageEvent = Alarm.GetEvent(this, receivedMessage); break; case (byte)CommandClass.SensorAlarm: messageEvent = SensorAlarm.GetEvent(this, receivedMessage); break; case (byte)CommandClass.SceneActivation: messageEvent = SceneActivation.GetEvent(this, receivedMessage); break; case (byte)CommandClass.SwitchBinary: messageEvent = SwitchBinary.GetEvent(this, receivedMessage); break; case (byte)CommandClass.SwitchMultilevel: messageEvent = SwitchMultilevel.GetEvent(this, receivedMessage); break; case (byte)CommandClass.SensorBinary: messageEvent = SensorBinary.GetEvent(this, receivedMessage); break; case (byte)CommandClass.SensorMultilevel: messageEvent = SensorMultilevel.GetEvent(this, receivedMessage); break; case (byte)CommandClass.Meter: messageEvent = Meter.GetEvent(this, receivedMessage); break; case (byte)CommandClass.ThermostatMode: case (byte)CommandClass.ThermostatFanMode: case (byte)CommandClass.ThermostatFanState: case (byte)CommandClass.ThermostatHeating: case (byte)CommandClass.ThermostatOperatingState: case (byte)CommandClass.ThermostatSetBack: case (byte)CommandClass.ThermostatSetPoint: messageEvent = Thermostat.GetEvent(this, receivedMessage); break; case (byte)CommandClass.UserCode: messageEvent = UserCode.GetEvent(this, receivedMessage); break; case (byte)CommandClass.Association: messageEvent = Association.GetEvent(this, receivedMessage); break; case (byte)CommandClass.Configuration: messageEvent = Configuration.GetEvent(this, receivedMessage); break; case (byte)CommandClass.WakeUp: messageEvent = WakeUp.GetEvent(this, receivedMessage); break; case (byte)CommandClass.Battery: messageEvent = Battery.GetEvent(this, receivedMessage); break; case (byte)CommandClass.Hail: Basic.Get(this); break; case (byte)CommandClass.MultiInstance: messageEvent = MultiInstance.GetEvent(this, receivedMessage); break; case (byte)CommandClass.ManufacturerSpecific: messageEvent = ManufacturerSpecific.GetEvent(this, receivedMessage); if (messageEvent != null) { var specs = (ManufacturerSpecificInfo)messageEvent.Value; this.ManufacturerId = specs.ManufacturerId; this.TypeId = specs.TypeId; this.ProductId = specs.ProductId; if (ManufacturerSpecificResponse != null) { try { ManufacturerSpecificResponse(this, new ManufacturerSpecificResponseEventArg() { NodeId = this.NodeId, ManufacturerSpecific = specs }); } catch (Exception ex) { Console.WriteLine("ZWaveLib: Error during ManufacturerSpecificResponse callback, " + ex.Message + "\n" + ex.StackTrace); } } } break; } } if (messageEvent != null) { this.RaiseUpdateParameterEvent(messageEvent.Instance, messageEvent.Event, messageEvent.Value); } else if (messageLength > 3) { if (receivedMessage[3] != 0x13) { bool log = true; if (messageLength > 7 && /* cmd_class */ receivedMessage[7] == (byte)CommandClass.ManufacturerSpecific) { log = false; } if (log) { Console.WriteLine("ZWaveLib UNHANDLED message: " + Utility.ByteArrayToString(receivedMessage)); } } } return(false); }