public PoolWeatherFeatureBase(HassMqttManager hassMqttManager, string displayName, string measurement, string unit, HassDeviceClass deviceClass = HassDeviceClass.None) : base(hassMqttManager) { _displayName = displayName; _measurement = measurement; _unit = unit; _deviceClass = deviceClass; }
public SetSetpointCommand(ILogger <SetSetpointCommand> logger, UhomeUponorClient client, FeatureManager featureManager, HassMqttManager hassMqttManager) { _logger = logger; _client = client; _featureManager = featureManager; _hassMqttManager = hassMqttManager; }
public SetPumpScheduleCommand(ILogger <SetPumpScheduleCommand> logger, HassMqttManager hassMqttManager, FeatureUpdateManager updateManager, BlueClient blueClient) { _logger = logger; _hassMqttManager = hassMqttManager; _updateManager = updateManager; _blueClient = blueClient; }
public SingleBlueRiiotPoolUpdaterFactory(ILoggerFactory loggerFactory, HassMqttManager hassMqttManager, FeatureUpdateManager updateManager, BlueClient blueClient, IOptions <BlueRiiotConfiguration> config) { _loggerFactory = loggerFactory; _hassMqttManager = hassMqttManager; _updateManager = updateManager; _blueClient = blueClient; _config = config.Value; }
public UponorConnectedService(HassMqttManager hassMqttManager, UhomeUponorClient uponorClient) { _hassMqttManager = hassMqttManager; _uponorClient = uponorClient; _version = typeof(Program).Assembly.GetName().Version.ToString(3); }
public static ISensorContainer GetSensor(this HassMqttManager manager, string deviceId, string entityId) { if (manager.TryGetSensor(deviceId, entityId, out var sensor)) { return(sensor); } throw new InvalidOperationException($"Unable to find sensor {deviceId}/{entityId} - is it configured?"); }
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 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(); }
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(); }
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); }
public BlueRiiotMqttService( ILogger <BlueRiiotMqttService> logger, IOptions <BlueRiiotConfiguration> config, BlueClient blueClient, HassMqttManager hassMqttManager, SingleBlueRiiotPoolUpdaterFactory updaterFactory) { _logger = logger; _blueClient = blueClient; _hassMqttManager = hassMqttManager; _updaterFactory = updaterFactory; _config = config.Value; }
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(); }
public HassConnectedEntityService(IOptions <HassConnectedEntityServiceConfig> options, IManagedMqttClient mqttClient, MqttEvents mqttEvents, HassMqttManager hassMqttManager, HassMqttTopicBuilder topicBuilder) { _config = options.Value; _mqttClient = mqttClient; _mqttEvents = mqttEvents; _hassMqttManager = hassMqttManager; StateTopic = topicBuilder.GetServiceTopic(_config.DeviceId, _config.EntityId, "state"); }
protected override void UpdateInternal(SwimmingPool pool, SwimmingPool _) { ISensorContainer sensor = HassMqttManager.GetSensor(HassUniqueIdBuilder.GetPoolDeviceId(pool), "pump_schedule"); SwimmingPoolCharacteristicsFilterPump pump = pool.Characteristics?.FilterPump; if (pump == null) { return; } MqttAttributesTopic attributes = sensor.GetAttributesSender(); // The new schedule may have fewer time ranges attributes.Clear(); sensor.SetPoolAttributes(pool); if (!pump.IsPresent) { // No pump sensor.SetValue(HassTopicKind.State, "None"); } else if (pump.OperatingType == "Manual") { // Pump exists, but is not scheduled sensor.SetValue(HassTopicKind.State, "Manual"); } else if (pump.OperatingType == "Scheduled") { sensor.SetValue(HassTopicKind.State, "Scheduled"); if (pump.OperatingHours != null && pump.OperatingHours.Any()) { string allTimes = string.Join(", ", pump.OperatingHours.Select(s => s.Start.ToString(TimeFormat) + "-" + s.End.ToString(TimeFormat))); attributes.SetAttribute("schedule", allTimes); attributes.SetAttribute("schedules", pump.OperatingHours.Count); for (int index = 0; index < pump.OperatingHours.Count; index++) { TimeRange range = pump.OperatingHours[index]; attributes.SetAttribute($"schedule_{index}", $"{range.Start.ToString(TimeFormat)}-{range.End.ToString(TimeFormat)}"); attributes.SetAttribute($"schedule_{index}_start", range.Start.ToString(TimeFormat)); attributes.SetAttribute($"schedule_{index}_end", range.End.ToString(TimeFormat)); } } } }
public UponorThermostatsService( ILogger <UponorThermostatsService> logger, IOptions <UponorConfiguration> config, FeatureManager featureManager, UhomeUponorClient uponorClient, HassMqttManager hassMqttManager, SystemDetailsContainer detailsContainer) { _logger = logger; _featureManager = featureManager; _uponorClient = uponorClient; _hassMqttManager = hassMqttManager; _detailsContainer = detailsContainer; _config = config.Value; }
public override void Process(UponorResponseContainer values) { // Average temperature if (!values.TryGetValue(UponorObjects.System(UponorSystem.AverageRoomTemperature), UponorProperties.Value, out object val)) { return; } string deviceId = HassUniqueIdBuilder.GetUhomeDeviceId(); ISensorContainer sensor = HassMqttManager.GetSensor(deviceId, "average_temperature"); MqttStateValueTopic sender = sensor.GetValueSender(HassTopicKind.State); sender.Value = val; }
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)); }
public UponorDiscoveryService( ILogger <UponorDiscoveryService> logger, IOptions <UponorConfiguration> config, IOptions <UponorOperationConfiguration> operationConfig, FeatureManager featureManager, UhomeUponorClient uponorClient, SystemDetailsContainer detailsContainer, HassMqttManager hassMqttManager) { _logger = logger; _operationConfig = operationConfig.Value; _uponorClient = uponorClient; _featureManager = featureManager; _detailsContainer = detailsContainer; _hassMqttManager = hassMqttManager; _config = config.Value; }
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); } }
public override void Process(UponorResponseContainer values) { string deviceId = HassUniqueIdBuilder.GetUhomeDeviceId(); if (!HassMqttManager.TryGetSensor(deviceId, "uhome", out ISensorContainer sensor)) { return; } sensor.SetValue(HassTopicKind.State, "discovered"); if (values.TryGetValue(UponorObjects.System(UponorSystem.DeviceObject), UponorProperties.ApplicationVersion, out object val)) { sensor.SetAttribute("application_version", val); } if (values.TryGetValue(UponorObjects.System(UponorSystem.DeviceObject), UponorProperties.DeviceName, out val)) { sensor.SetAttribute("device_name", val); } if (values.TryGetValue(UponorObjects.System(UponorSystem.DeviceObject), UponorProperties.DeviceId, out val)) { sensor.SetAttribute("device_id", val); } if (values.TryGetValue(UponorObjects.System(UponorSystem.DeviceObject), UponorProperties.SerialNumber, out val)) { sensor.SetAttribute("serial_number", val); } if (values.TryGetValue(UponorObjects.System(UponorSystem.DeviceObject), UponorProperties.ProductName, out val)) { sensor.SetAttribute("product_name", val); } if (values.TryGetValue(UponorObjects.System(UponorSystem.DeviceObject), UponorProperties.Supplier, out val)) { sensor.SetAttribute("supplier", val); } if (values.TryGetValue(UponorObjects.System(UponorSystem.DeviceObject), UponorProperties.MacAddress, out val)) { sensor.SetAttribute("macaddress", val); } }
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(); }
public override void Process(UponorResponseContainer values) { // Outdoor sensors foreach (int controller in _systemDetails.GetAvailableOutdoorSensors()) { if (!values.TryGetValue(UponorObjects.Controller(UponorController.MeasuredOutdoorTemperature, controller), UponorProperties.Value, out object val)) { continue; } string deviceId = HassUniqueIdBuilder.GetControllerDeviceId(controller); ISensorContainer sensor = HassMqttManager.GetSensor(deviceId, "outdoor_sensor"); MqttStateValueTopic sender = sensor.GetValueSender(HassTopicKind.State); sender.Value = val; } }
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"); }
public override void Process(UponorResponseContainer values) { // Software versions foreach (int controller in _systemDetails.GetAvailableControllers()) { if (!values.TryGetValue(UponorObjects.Controller(UponorController.ControllerSwVersion, controller), UponorProperties.Value, out object val)) { continue; } string deviceId = HassUniqueIdBuilder.GetControllerDeviceId(controller); ISensorContainer sensor = HassMqttManager.GetSensor(deviceId, "controller"); MqttStateValueTopic sender = sensor.GetValueSender(HassTopicKind.State); MqttAttributesTopic attributes = sensor.GetAttributesSender(); sender.Value = "discovered"; attributes.SetAttribute("sw_version", val); } }
public override void Process(UponorResponseContainer values) { foreach ((int controller, int thermostat) in _systemDetails.GetAvailableThermostats()) { string deviceId = HassUniqueIdBuilder.GetThermostatDeviceId(controller, thermostat); // Temperature ISensorContainer sensor = HassMqttManager.GetSensor(deviceId, "temperature"); MqttStateValueTopic sender = sensor.GetValueSender(HassTopicKind.State); if (values.TryGetValue(UponorObjects.Thermostat(UponorThermostats.RoomTemperature, controller, thermostat), UponorProperties.Value, out float floatVal)) { if (IsValid.Temperature(floatVal)) { sender.Value = floatVal; } else { _logger.LogWarning("Received an invalid temperature of {Value} for {Device}", floatVal, deviceId); } } } }
public PoolTemperatureFeature(HassMqttManager hassMqttManager) : base(hassMqttManager, "Temperature status", "temperature") { }
public PoolCyaFeature(HassMqttManager hassMqttManager) : base(hassMqttManager, "Cyuranic Acid status", "cya") { }
public PoolPhFeature(HassMqttManager hassMqttManager) : base(hassMqttManager, "pH status", "ph") { }
public PoolTaFeature(HassMqttManager hassMqttManager) : base(hassMqttManager, "Total Alkalinity status", "ta") { }