Skip to content

Commit

Permalink
Remove battery sensor
Browse files Browse the repository at this point in the history
Fixes #62
  • Loading branch information
LordMike committed Sep 26, 2021
1 parent 8ffc7e5 commit f6e99fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
22 changes: 3 additions & 19 deletions MBW.BlueRiiot2MQTT/Features/BlueDevice/BlueDeviceFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,9 @@ protected override void CreateSensor(SwimmingPool pool, SwimmingPoolDevice data)
})
.ConfigureAliveService();

HassMqttManager.ConfigureSensor<MqttSensor>(deviceId, "battery")
.ConfigureTopics(HassTopicKind.State, HassTopicKind.JsonAttributes)
.ConfigureDevice(deviceConfigure)
.ConfigureDiscovery(discovery =>
{
discovery.DeviceClass = HassSensorDeviceClass.Battery;
discovery.Name = $"{namePrefix} Battery";
discovery.UnitOfMeasurement = "%";
})
.ConfigureAliveService();
// Battery was previously done from "BatteryLow" API response
// But this value is nonfunctional (https://github.com/LordMike/MBW.BlueRiiot2MQTT/issues/62#issuecomment-925086790)
HassMqttManager.RemoveSensor<MqttSensor>(deviceId, "battery");

HassMqttManager.ConfigureSensor<MqttSensor>(deviceId, "status")
.ConfigureTopics(HassTopicKind.State, HassTopicKind.JsonAttributes)
Expand All @@ -78,9 +71,6 @@ protected override void UpdateInternal(SwimmingPool pool, SwimmingPoolDevice dat
ISensorContainer deviceSensor = HassMqttManager
.GetSensor(deviceId, "device")
.SetPoolAttributes(pool);
ISensorContainer batterySensor = HassMqttManager
.GetSensor(deviceId, "battery")
.SetPoolAttributes(pool);
ISensorContainer statusSensor = HassMqttManager
.GetSensor(deviceId, "status")
.SetPoolAttributes(pool);
Expand All @@ -102,12 +92,6 @@ protected override void UpdateInternal(SwimmingPool pool, SwimmingPoolDevice dat
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);
}
Expand Down
2 changes: 1 addition & 1 deletion MBW.BlueRiiot2MQTT/MBW.BlueRiiot2MQTT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="Enums.NET" Version="3.0.3" />
<PackageReference Include="Humanizer.Core" Version="2.8.26" />
<PackageReference Include="MBW.Client.BlueRiiotAPI" Version="0.8.5" />
<PackageReference Include="MBW.HassMQTT.CommonServices" Version="3.3.2" />
<PackageReference Include="MBW.HassMQTT.CommonServices" Version="3.4.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.KeyPerFile" Version="3.1.6" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.6" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.6" />
Expand Down

0 comments on commit f6e99fc

Please sign in to comment.