public void Process(SwimmingPool pool, object obj) { foreach (FeatureUpdaterBase updater in _updaters) { updater.Update(pool, obj); } }
private void button1_Click(object sender, EventArgs e) { try { int result = SwimmingPool.saveSwimming( textName.Text, textSurname.Text, textNumber.Text, comboBoxDay.SelectedItem.ToString(), comboBoxTime.SelectedItem.ToString() ); if (result != 0) { MessageBox.Show("Your appointment has been approved."); } else { MessageBox.Show("Please,try again."); } } catch (Exception exp) { throw new Exception(exp.Message); } }
public SingleBlueRiiotPoolUpdater Create(SwimmingPool pool) { // TODO: Add structured logging property to indicate pool ILogger <SingleBlueRiiotPoolUpdater> logger = _loggerFactory.CreateLogger <SingleBlueRiiotPoolUpdater>(); return(new SingleBlueRiiotPoolUpdater(logger, _hassMqttManager, _updateManager, _blueClient, _config, pool)); }
protected override void Update(ISensorContainer sensor, SwimmingPool pool, SwimmingPoolWeather obj) { sensor.SetAttribute("temp_min", obj.TemperatureMin); sensor.SetAttribute("temp_max", obj.TemperatureMax); sensor.SetValue(HassTopicKind.State, obj.TemperatureCurrent); }
public ActionResult DeleteConfirmed(int id) { SwimmingPool swimmingPool = db.SwimmingPool.Find(id); db.SwimmingPool.Remove(swimmingPool); db.SaveChanges(); return(RedirectToAction("Index")); }
public void TryDecoratorWithSmallHouse() { House house = new SmallWoodenHouse(); var smallHouseCost = house.GetCost(); house = new SwimmingPool(house); var smallHouseCostWithSwimmingPool = house.GetCost(); Assert.True(smallHouseCost < smallHouseCostWithSwimmingPool); }
protected sealed override void UpdateInternal(SwimmingPool pool, SwimmingPoolWeather obj) { ISensorContainer sensor = HassMqttManager.GetSensor(HassUniqueIdBuilder.GetPoolDeviceId(pool), _measurement); Update(sensor, pool, obj); sensor .SetAttribute("timestamp", obj.Timestamp) .SetPoolAttributes(pool); }
protected override void Update(ISensorContainer sensor, SwimmingPool pool, SwimmingPoolWeather obj) { sensor.SetAttribute("temp_min", obj.TemperatureMin); sensor.SetAttribute("temp_max", obj.TemperatureMax); sensor.SetAttribute("temp", obj.TemperatureCurrent); sensor.SetAttribute("wind_speed", obj.WindSpeedCurrent); sensor.SetAttribute("uv", obj.UvCurrent); sensor.SetValue(HassTopicKind.State, obj.WeatherCurrentDescription); }
public ActionResult Edit([Bind(Include = "Id,Name,Address")] SwimmingPool swimmingPool) { if (ModelState.IsValid) { db.Entry(swimmingPool).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(swimmingPool)); }
static void Main(string[] args) { SwimmingPool basein = new SwimmingPool(2, 2, 2); basein.PoolFull += SwimmingPool.Pool_Full; basein.PoolEmpty += SwimmingPool.Pool_Empty; basein.AddWater(4000); basein.RemoveWater(4000); basein.AddWater(8000); Console.ReadKey(); }
public void Update(SwimmingPool pool, object obj) { if (!AppliesTo(pool, obj)) { return; } CreateSensor(pool, obj); UpdateInternal(pool, obj); }
protected override void CreateSensor(SwimmingPool pool, SwimmingPoolGuidanceGetResponse guidance) { HassMqttManager.ConfigureSensor <MqttSensor>(HassUniqueIdBuilder.GetPoolDeviceId(pool), "guidance") .ConfigureTopics(HassTopicKind.State, HassTopicKind.JsonAttributes) .SetHassPoolProperties(pool) .ConfigureDiscovery(discovery => { discovery.Name = $"{pool.Name} Guidance"; }) .ConfigureAliveService(); }
protected override void CreateSensor(SwimmingPool pool, List <SwimmingPoolLastMeasurementsGetResponse> measurements, SwimmingPoolLastMeasurementsGetResponse latest) { HassMqttManager.ConfigureSensor <MqttSensor>(HassUniqueIdBuilder.GetPoolDeviceId(pool), $"{_measurement}_status") .ConfigureTopics(HassTopicKind.State, HassTopicKind.JsonAttributes) .SetHassPoolProperties(pool) .ConfigureDiscovery(discovery => { discovery.Name = $"{pool.Name} {_displayName}"; }) .ConfigureAliveService(); }
public ActionResult Create([Bind(Include = "Id,Name,Address")] SwimmingPool swimmingPool) { if (ModelState.IsValid) { db.SwimmingPool.Add(swimmingPool); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(swimmingPool)); }
public SingleBlueRiiotPoolUpdater(ILogger logger, HassMqttManager hassMqttManager, FeatureUpdateManager updateManager, BlueClient blueClient, BlueRiiotConfiguration config, SwimmingPool pool) { _logger = logger; _hassMqttManager = hassMqttManager; _pool = pool; _updateManager = updateManager; _blueClient = blueClient; _config = config; _delayCalculator = new DelayCalculator(_logger, config, pool.Name); _backgroundTask = new Task(async() => await Run(), _stoppingToken.Token); }
protected override void CreateSensor(SwimmingPool pool, SwimmingPoolWeather obj) { HassMqttManager.ConfigureSensor <MqttSensor>(HassUniqueIdBuilder.GetPoolDeviceId(pool), _measurement) .ConfigureTopics(HassTopicKind.State, HassTopicKind.JsonAttributes) .SetHassPoolProperties(pool) .ConfigureDiscovery(discovery => { discovery.Name = $"{pool.Name} {_displayName}"; discovery.DeviceClass = _deviceClass; discovery.UnitOfMeasurement = _unit; }) .ConfigureAliveService(); }
// GET: SwimmingPools/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SwimmingPool swimmingPool = db.SwimmingPool.Find(id); if (swimmingPool == null) { return(HttpNotFound()); } return(View(swimmingPool)); }
private void button3_Click(object sender, EventArgs e) { swlist sw = new swlist(); sw.Show(); try { SwimmingPool s = new SwimmingPool(); dgvSwimming = s.ListSwimming(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
protected override void UpdateInternal(SwimmingPool pool, List <SwimmingPoolLastMeasurementsGetResponse> measurements, SwimmingPoolLastMeasurementsGetResponse latest) { ISensorContainer sensor = HassMqttManager .GetSensor(HassUniqueIdBuilder.GetPoolDeviceId(pool), "last_measurement") .SetPoolAttributes(pool); if (latest == null) { // No measurements sensor.SetValue(HassTopicKind.State, null); sensor.SetAttribute(AttributeMeasurement, "none"); return; } SwpLastMeasurements lastMeasurement = null; if (latest.LastBlueMeasureTimestamp.HasValue && (!latest.LastStripTimestamp.HasValue || latest.LastBlueMeasureTimestamp > latest.LastStripTimestamp)) { // Blue measurement is latest lastMeasurement = latest.Data.OrderByDescending(s => s.Timestamp).FirstOrDefault(); sensor.SetValue(HassTopicKind.State, latest.LastBlueMeasureTimestamp); sensor.SetAttribute("method", "blue"); } else if (latest.LastStripTimestamp.HasValue) { // Strip measurement is latest lastMeasurement = latest.Data.OrderByDescending(s => s.Timestamp).FirstOrDefault(); sensor.SetValue(HassTopicKind.State, latest.LastStripTimestamp); sensor.SetAttribute("method", "strip"); } else { // No measurements sensor.SetAttribute(AttributeMeasurement, "none"); sensor.SetValue(HassTopicKind.State, null); } if (lastMeasurement != null) { sensor.SetAttribute(AttributeMeasurement, lastMeasurement.Name); } }
protected override void UpdateInternal(SwimmingPool pool, List <SwimmingPoolLastMeasurementsGetResponse> measurements, SwimmingPoolLastMeasurementsGetResponse latest) { if (!TryGetMeasurement(latest.Data, out SwpLastMeasurements measurement)) { return; } ISensorContainer sensor = HassMqttManager .GetSensor(HassUniqueIdBuilder.GetPoolDeviceId(pool), $"{_measurement}_status") .SetPoolAttributes(pool); MeasurementUtility.AddAttributes(sensor.GetAttributesSender(), measurement); MeasurementStatus status = MeasurementUtility.GetStatus(measurement); sensor.SetValue(HassTopicKind.State, status.AsString(EnumFormat.EnumMemberValue)); }
protected override void CreateSensor(SwimmingPool pool, SwimmingPoolDevice data) { string deviceId = HassUniqueIdBuilder.GetBlueDeviceId(data); string deviceName = $"Blue {data.BlueDevice.HwType.Humanize(LetterCasing.Title)} v{data.BlueDevice.HwGeneration} ({data.BlueDevice.HwRegion.Humanize(LetterCasing.AllCaps)}) Device {data.BlueDevice.Serial}"; string namePrefix = $"Blue {data.BlueDeviceSerial}"; SensorExtensions.DeviceConfigure deviceConfigure = device => { device.Identifiers = new[] { deviceId }; device.Name = deviceName; device.SwVersion = data.BlueDevice.FwVersionPsoc; device.Manufacturer = "Blue Riiot"; device.Model = $"Blue {data.BlueDevice.HwType.Humanize(LetterCasing.Title)} v{data.BlueDevice.HwGeneration} ({data.BlueDevice.HwRegion.Humanize(LetterCasing.AllCaps)})"; }; HassMqttManager.ConfigureSensor <MqttSensor>(deviceId, "device") .ConfigureTopics(HassTopicKind.State, HassTopicKind.JsonAttributes) .ConfigureDevice(deviceConfigure) .ConfigureDiscovery(discovery => { discovery.DeviceClass = HassDeviceClass.Timestamp; discovery.Name = $"{namePrefix} Last Contact"; }) .ConfigureAliveService(); HassMqttManager.ConfigureSensor <MqttSensor>(deviceId, "battery") .ConfigureTopics(HassTopicKind.State, HassTopicKind.JsonAttributes) .ConfigureDevice(deviceConfigure) .ConfigureDiscovery(discovery => { discovery.DeviceClass = HassDeviceClass.Battery; discovery.Name = $"{namePrefix} Battery"; discovery.UnitOfMeasurement = "%"; }) .ConfigureAliveService(); HassMqttManager.ConfigureSensor <MqttSensor>(deviceId, "status") .ConfigureTopics(HassTopicKind.State, HassTopicKind.JsonAttributes) .ConfigureDevice(deviceConfigure) .ConfigureDiscovery(discovery => { discovery.Name = $"{namePrefix} Status"; }) .ConfigureAliveService(); }
protected override void UpdateInternal(SwimmingPool pool, SwimmingPoolDevice data) { string deviceId = HassUniqueIdBuilder.GetBlueDeviceId(data); ISensorContainer deviceSensor = HassMqttManager .GetSensor(deviceId, "device") .SetPoolAttributes(pool); ISensorContainer batterySensor = HassMqttManager .GetSensor(deviceId, "battery") .SetPoolAttributes(pool); ISensorContainer statusSensor = HassMqttManager .GetSensor(deviceId, "status") .SetPoolAttributes(pool); // Device // Determine last contact DateTime?latestContact = ComparisonHelper.GetMax(data.Created, data.BlueDevice.LastHelloMessageV, data.BlueDevice.LastMeasureMessage, data.BlueDevice.LastMeasureMessageBle, data.BlueDevice.LastMeasureMessageSigfox); deviceSensor.SetValue(HassTopicKind.State, latestContact); // Device attributes deviceSensor.SetAttribute("serial", data.BlueDevice.Serial); deviceSensor.SetAttribute("serial_number", data.BlueDevice.Sn); deviceSensor.SetAttribute("wake_interval", data.BlueDevice.WakePeriod); deviceSensor.SetAttribute("firmware", data.BlueDevice.FwVersionPsoc); deviceSensor.SetAttribute("firmware_installed", data.BlueDevice.FwVersionHistory?.OrderByDescending(s => s.Timestamp).Select(s => s.Timestamp).FirstOrDefault()); // Battery if (data.BlueDevice.BatteryLow) { batterySensor.SetValue(HassTopicKind.State, 10); } else { batterySensor.SetValue(HassTopicKind.State, 100); } // Status (awake, sleeping, ..) statusSensor.SetValue(HassTopicKind.State, data.BlueDevice.SleepState); }
protected override void UpdateInternal(SwimmingPool pool, SwimmingPoolGuidanceGetResponse guidance) { ISensorContainer sensor = HassMqttManager .GetSensor(HassUniqueIdBuilder.GetPoolDeviceId(pool), "guidance") .SetPoolAttributes(pool); if (guidance.Guidance?.IssueToFix == null) { sensor.SetValue(HassTopicKind.State, "No guidance at this time"); sensor.SetAttribute("status", "ok"); return; } string text = $"{guidance.Guidance.IssueToFix.IssueTitle}: {guidance.Guidance.IssueToFix.ActionTitle}"; sensor.SetValue(HassTopicKind.State, text); sensor.SetAttribute("status", "alert"); }
protected override bool AppliesTo(SwimmingPool pool, List <SwimmingPoolLastMeasurementsGetResponse> measurements, SwimmingPoolLastMeasurementsGetResponse latest) { return(latest != null && TryGetMeasurement(latest.Data, out _)); }
protected override void Update(ISensorContainer sensor, SwimmingPool pool, SwimmingPoolWeather obj) { sensor.SetValue(HassTopicKind.State, obj.UvCurrent); }
protected abstract void Update(ISensorContainer sensor, SwimmingPool pool, SwimmingPoolWeather obj);
protected abstract void CreateSensor(SwimmingPool pool, List <SwimmingPoolLastMeasurementsGetResponse> measurements, SwimmingPoolLastMeasurementsGetResponse latest);
protected override bool AppliesTo(SwimmingPool pool, SwimmingPoolDevice data) { return(data.BlueDevice != null); }
private void swlist_Load(object sender, EventArgs e) { dgvSwimming.DataSource = SwimmingPool.ShowSwimming(); }
public async Task <SwimmingPool> PutSwimmingPool(string poolId, SwimmingPool swimmingPool, CancellationToken token = default) { return(await PerformPut <SwimmingPool, SwimmingPool>($"swimming_pool/{HttpUtility.UrlEncode(poolId)}", swimmingPool, token)); }