From f67e803af5c5e70c4e7a99b43960f9390e9f9f92 Mon Sep 17 00:00:00 2001 From: Alexander Pohl Date: Sat, 5 Sep 2020 12:57:05 +0200 Subject: [PATCH] report battery level again in percent --- .../atc_mithermometer/atc_mithermometer.cpp | 15 +++++++++------ esphome/components/atc_mithermometer/sensor.py | 7 +++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/esphome/components/atc_mithermometer/atc_mithermometer.cpp b/esphome/components/atc_mithermometer/atc_mithermometer.cpp index 9e0b9d018b..2016b435d4 100644 --- a/esphome/components/atc_mithermometer/atc_mithermometer.cpp +++ b/esphome/components/atc_mithermometer/atc_mithermometer.cpp @@ -92,12 +92,15 @@ bool ATCMiThermometer::parse_message(const std::vector &message, ParseR const int16_t temperature = uint16_t(data[7]) | (uint16_t(data[6]) << 8); result.temperature = temperature / 10.0f; - // humidity, 1 byte, 8-bit unsigned integer, 0.1 % + // humidity, 1 byte, 8-bit unsigned integer, 1.0 % result.humidity = data[8]; - // battery, 1 byte, 8-bit unsigned integer, 0.001 V - const int16_t battery_level = uint16_t(data[11]) | (uint16_t(data[10]) << 8); - result.battery_level = battery_level / 1.0e3f; + // battery, 1 byte, 8-bit unsigned integer, 1.0 % + result.battery_level = data[9]; + + // battery, 2 bytes, 16-bit unsigned integer, 0.001 V + // const int16_t battery_level = uint16_t(data[11]) | (uint16_t(data[10]) << 8); + // result.battery_level = battery_level / 1.0e3f; return true; } @@ -114,10 +117,10 @@ bool ATCMiThermometer::report_results(const optional &result, const ESP_LOGD(TAG, " Temperature: %.1f °C", *result->temperature); } if (result->humidity.has_value()) { - ESP_LOGD(TAG, " Humidity: %.1f %%", *result->humidity); + ESP_LOGD(TAG, " Humidity: %.0f %%", *result->humidity); } if (result->battery_level.has_value()) { - ESP_LOGD(TAG, " Battery Level: %.3f V", *result->battery_level); + ESP_LOGD(TAG, " Battery Level: %.0f %%", *result->battery_level); } return true; diff --git a/esphome/components/atc_mithermometer/sensor.py b/esphome/components/atc_mithermometer/sensor.py index 3c98c2367c..c4f2dbb1c1 100644 --- a/esphome/components/atc_mithermometer/sensor.py +++ b/esphome/components/atc_mithermometer/sensor.py @@ -2,8 +2,7 @@ import esphome.codegen as cg import esphome.config_validation as cv from esphome.components import sensor, esp32_ble_tracker from esphome.const import CONF_BATTERY_LEVEL, CONF_HUMIDITY, CONF_MAC_ADDRESS, CONF_TEMPERATURE, \ - UNIT_CELSIUS, ICON_THERMOMETER, UNIT_PERCENT, ICON_WATER_PERCENT, ICON_BATTERY, CONF_ID, \ - UNIT_VOLT + UNIT_CELSIUS, ICON_THERMOMETER, UNIT_PERCENT, ICON_WATER_PERCENT, ICON_BATTERY, CONF_ID DEPENDENCIES = ['esp32_ble_tracker'] @@ -16,8 +15,8 @@ CONFIG_SCHEMA = cv.Schema({ cv.GenerateID(): cv.declare_id(ATCMiThermometer), cv.Required(CONF_MAC_ADDRESS): cv.mac_address, cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(UNIT_CELSIUS, ICON_THERMOMETER, 1), - cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(UNIT_PERCENT, ICON_WATER_PERCENT, 1), - cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(UNIT_VOLT, ICON_BATTERY, 3), + cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(UNIT_PERCENT, ICON_WATER_PERCENT, 0), + cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(UNIT_PERCENT, ICON_BATTERY, 0), }).extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA).extend(cv.COMPONENT_SCHEMA)