Skip to content

Commit

Permalink
Fix negative outdoor temperature sensor values
Browse files Browse the repository at this point in the history
  • Loading branch information
wrfz committed Nov 16, 2024
1 parent b64b684 commit 2ece074
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion components/daikin_rotex_can/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@
"data_offset": 5,
"data_size": 2,
"divider": 10.0,
"signed": True,
"range": [-30, 90]
},
{
Expand Down Expand Up @@ -1293,8 +1294,8 @@
}
]

CODEOWNERS = ["@wrfz"]
DEPENDENCIES = []

AUTO_LOAD = ['binary_sensor', 'button', 'number', 'sensor', 'select', 'text', 'text_sensor']

CONF_CAN_ID = "canbus_id"
Expand Down Expand Up @@ -1561,6 +1562,7 @@ async def set_lambda():
sens_conf.get("data_offset", 5),
sens_conf.get("data_size", 1),
divider,
sens_conf.get("signed", False),
sens_conf.get("update_entity", ""),
update_interval,
await handle_lambda(),
Expand Down
4 changes: 4 additions & 0 deletions components/daikin_rotex_can/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class TEntity {
uint8_t data_offset;
uint8_t data_size;
float divider;
bool isSigned;
std::string update_entity;
uint16_t update_interval;
THandleFunc handle_lambda;
Expand All @@ -43,6 +44,7 @@ class TEntity {
, data_offset(0)
, data_size(0)
, divider(1)
, isSigned(false)
, update_entity({})
, update_interval(1000)
, handle_lambda([](TMessage const&){ return 0; })
Expand All @@ -60,6 +62,7 @@ class TEntity {
uint8_t _data_offset,
uint8_t _data_size,
float _divider,
bool _isSigned,
std::string const& _update_entity,
uint16_t _update_interval,
THandleFunc _handle_lambda,
Expand All @@ -74,6 +77,7 @@ class TEntity {
, data_offset(_data_offset)
, data_size(_data_size)
, divider(_divider)
, isSigned(_isSigned)
, update_entity(_update_entity)
, update_interval(_update_interval)
, handle_lambda(_handle_lambda)
Expand Down
7 changes: 6 additions & 1 deletion components/daikin_rotex_can/sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ static const char* TAG = "daikin_rotex_can";

bool CanSensor::handleValue(uint16_t value, TEntity::TVariant& current, TVariant& previous) {
previous = state;
current = value / m_config.divider;
if (m_config.isSigned) {
current = static_cast<int16_t>(value) / m_config.divider;
} else {
current = value / m_config.divider;
}

const float float_value = std::get<float>(current);
const bool valid = !m_range.required() || (float_value >= m_range.min && float_value <= m_range.max);
if (valid) {
Expand Down

0 comments on commit 2ece074

Please sign in to comment.