Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
wrfz committed Sep 15, 2024
2 parents 6001ac5 + abab933 commit 0347a57
Show file tree
Hide file tree
Showing 24 changed files with 2,783 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 wrfz

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
106 changes: 106 additions & 0 deletions components/daikin_rotex_can/Accessor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#pragma once

#include "esphome/components/sensor/sensor.h"
#include "esphome/components/text/text.h"
#include "esphome/components/text_sensor/text_sensor.h"
#include "esphome/components/daikin_rotex_can/BidiMap.h"
#include "esphome/components/daikin_rotex_can/utils.h"
#include <list>

namespace esphome {
namespace daikin_rotex_can {

class DaikinRotexCanComponent;

class Accessor {
using THandleFunc = std::function<float(TMessage const&)>;
using TSetFunc = std::function<void(TMessage&, float)>;

struct TEntityArguments {
EntityBase* pEntity;
std::string id;
TMessage command;
uint8_t data_offset;
uint8_t data_size;
float divider;
BidiMap<uint8_t, std::string> map;
std::string update_entity;
uint16_t update_interval;
THandleFunc handle_lambda;
TSetFunc set_lambda;
bool handle_lambda_set;
bool set_lambda_set;

TEntityArguments(
EntityBase* _pEntity,
std::string const& _id,
std::string const& _command,
uint8_t _data_offset,
uint8_t _data_size,
float _divider,
std::string const& _map,
std::string const& _update_entity,
uint16_t _update_interval,
THandleFunc _handle_lambda,
TSetFunc _set_lambda,
bool _handle_lambda_set,
bool _set_lambda_set
)
: pEntity(_pEntity)
, id(_id)
, command(Utils::str_to_bytes_array8(_command))
, data_offset(_data_offset)
, data_size(_data_size)
, divider(_divider)
, map(Utils::str_to_map(_map))
, update_entity(_update_entity)
, update_interval(_update_interval)
, handle_lambda(_handle_lambda)
, set_lambda(_set_lambda)
, handle_lambda_set(_handle_lambda_set)
, set_lambda_set(_set_lambda_set)
{}
};
using TEntityArgumentsList = std::list<TEntityArguments>;
public:
Accessor(DaikinRotexCanComponent* pDaikinRotexCanComponent)
: m_log_filter(nullptr)
, m_custom_request_text(nullptr)
, m_thermal_power(nullptr)
, m_pDaikinRotexCanComponent(pDaikinRotexCanComponent) {
}

DaikinRotexCanComponent* getDaikinRotexCanComponent() const {
return m_pDaikinRotexCanComponent;
}

TEntityArgumentsList const& get_entities() const { return m_entities; }
void set_entity(std::string const& name, TEntityArguments const& arg) { m_entities.push_back(arg); }

// Texts

text::Text* get_log_filter() const { return m_log_filter; }
void set_log_filter(text::Text* pText) { m_log_filter = pText; }

text::Text* get_custom_request_text() const { return m_custom_request_text; }
void set_custom_request_text(text::Text* pText) { m_custom_request_text = pText; }

// Sensors

sensor::Sensor* get_thermal_power() const { return m_thermal_power; }
void set_thermal_power(sensor::Sensor* pSensor) { m_thermal_power = pSensor; }

private:
text::Text* m_log_filter;
text::Text* m_custom_request_text;

TEntityArgumentsList m_entities;

// Sensors
sensor::Sensor* m_thermal_power;

DaikinRotexCanComponent* m_pDaikinRotexCanComponent;
};

}
}
52 changes: 52 additions & 0 deletions components/daikin_rotex_can/BidiMap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once

#include <sstream>
#include <map>

template<typename KeyType, typename ValueType>
class BidiMap {
public:
using Iterator = typename std::map<KeyType, ValueType>::const_iterator;

BidiMap(std::initializer_list<std::pair<const KeyType, ValueType>> init_list)
: key_to_value(init_list) {
for (const auto& pair : init_list) {
value_to_key[pair.second] = pair.first;
}
}

BidiMap(const std::map<KeyType, ValueType>& map)
: key_to_value(map) {
for (const auto& pair : map) {
value_to_key[pair.second] = pair.first;
}
}

Iterator findByKey(const KeyType& key) const {
return key_to_value.find(key);
}

Iterator findByValue(const ValueType& value) const {
auto it = value_to_key.find(value);
if (it != value_to_key.end()) {
return key_to_value.find(it->second);
}
return key_to_value.end();
}

Iterator end() const {
return key_to_value.end();
}

std::string string() const {
std::stringstream ss;
for (const auto& pair : key_to_value) {
ss << "{" << std::to_string(pair.first) << ", " << pair.second << "} ";
}
return ss.str();
}

private:
std::map<KeyType, ValueType> key_to_value;
std::map<ValueType, KeyType> value_to_key;
};
Loading

0 comments on commit 0347a57

Please sign in to comment.