15 const std::array<value_type, N>
table;
20 static_assert(N <= std::numeric_limits<uint8_t>::max());
21 if (value == Unknown) {
24 for (uint8_t i = 0; i < static_cast<uint8_t>(N); ++i) {
25 if (this->table[i] == value) {
34template<auto Unknown,
class T, std::
size_t N>
static constexpr auto make_map(
const T (&values)[N]) {
35 return LookupMap<Unknown, N>{std::to_array(values)};
44 static constexpr auto ID = PropertyId::POWER;
49 status.power_on = payload[2] != 0;
54 payload[3] =
status.power_on ? 0x01 : 0x00;
60 static constexpr auto ID = PropertyId::TEMPERATURE;
74 payload[14] =
static_cast<uint8_t
>(std::round(
status.target_temperature * 2.0f) + 128);
90 static constexpr auto ID = PropertyId::REMOTE_TEMPERATURE;
97 payload[2] =
static_cast<uint8_t
>(remote_temperature_half_deg - 16);
98 payload[3] =
static_cast<uint8_t
>(remote_temperature_half_deg + 128);
104 static constexpr float decode(
int temp_a,
int temp_b,
int delta) {
105 return temp_b != 0 ? (temp_b - 128) / 2.0f : delta + temp_a;
109 template<
typename Derived, auto Field>
struct Lookup {
110 using Value = std::remove_cvref_t<decltype(std::declval<Status>().*Field)>;
115 status.*Field = Derived::MAP.lookup(Derived::decode_raw(payload, ctx));
120 if (Derived::MAP.reverse_lookup(
status.*Field,
raw)) {
121 Derived::encode_raw(payload,
raw, ctx);
127 if (!Derived::MAP.reverse_lookup(value,
raw)) {
131 mask.set(Derived::ID);
137 constexpr Lookup() =
default;
141 static constexpr auto ID = PropertyId::MODE;
142 static constexpr auto MAP = make_map<MitsubishiCN105::Mode::UNKNOWN>({
155 const bool i_see = payload[3] > 0x08;
156 return payload[3] - (i_see ? 0x08 : 0);
166 static constexpr auto ID = PropertyId::FAN;
167 static constexpr auto MAP = make_map<MitsubishiCN105::FanMode::UNKNOWN>({
186 static constexpr auto ID = PropertyId::VANE;
187 static constexpr auto MAP = make_map<MitsubishiCN105::VaneMode::UNKNOWN>({
207 static constexpr auto ID = PropertyId::WIDE_VANE;
208 static constexpr auto MAP = make_map<MitsubishiCN105::WideVaneMode::UNKNOWN>({
242 if (this->payload.size() <= 10) {
250 if (this->payload.size() <= 5) {
258 template<
typename T,
typename Out> ESPHOME_ALWAYS_INLINE
void decode_one_(Out &out) {
259 T::decode_context(this->context, this->payload.data());
260 if constexpr (
requires { T::ID; }) {
261 if (this->pending_writes.contains(T::ID)) {
265 T::decode(out, this->payload.data(), this->context);
268 template<
typename... T,
typename Out>
void ESPHOME_ALWAYS_INLINE
decode_(Out &out) {
279 this->payload[0] = 0x01;
284 this->payload[0] = 0x07;
289 template<
typename... T,
typename In>
void ESPHOME_ALWAYS_INLINE
encode_and_clear_(
const In &in) {
291 (this->pending_writes.clear(T::ID), ...);
294 template<
typename T,
typename In>
void encode_one_(
const In &in) {
295 if (this->pending_writes.contains(T::ID)) {
296 T::encode(this->payload, in, this->context);
static constexpr uint8_t REMOTE_TEMPERATURE_DISABLED
constexpr value_type lookup(uint8_t raw) const
constexpr bool reverse_lookup(value_type value, uint8_t &out) const
decltype(Unknown) value_type
const std::array< value_type, N > table
bool set_wide_vane_high_bit
bool use_temperature_encoding_b
void ESPHOME_ALWAYS_INLINE decode_(Out &out)
bool ESPHOME_ALWAYS_INLINE decode_settings(Status &status)
const Mask & pending_writes
PropertyContext & context
const std::span< const uint8_t > payload
bool ESPHOME_ALWAYS_INLINE decode_room_temperature(Status &status)
ESPHOME_ALWAYS_INLINE void decode_one_(Out &out)
void ESPHOME_ALWAYS_INLINE encode_remote_temperature(uint8_t remote_temperature_half_deg)
void encode_one_(const In &in)
void ESPHOME_ALWAYS_INLINE encode_settings(const Status &status)
void ESPHOME_ALWAYS_INLINE encode_and_clear_(const In &in)
const PropertyContext & context
static constexpr auto MAP
static void encode_raw(uint8_t *payload, uint8_t raw, const PropertyContext &)
static uint8_t decode_raw(const uint8_t *payload, const PropertyContext &ctx)
static bool validate_and_set(Value value, Status &status, Mask &mask)
std::remove_cvref_t< decltype(std::declval< Status >().*Field)> Value
static void decode(Status &status, const uint8_t *payload, const PropertyContext &ctx)
static void encode(uint8_t *payload, const Status &status, const PropertyContext &ctx)
static void decode_context(PropertyContext &ctx, const uint8_t *payload)
static uint8_t decode_raw(const uint8_t *payload, const PropertyContext &ctx)
static void encode_raw(uint8_t *payload, uint8_t raw, const PropertyContext &)
static constexpr auto MAP
static void encode(uint8_t *payload, const Status &status, const PropertyContext &ctx)
static void decode(Status &status, const uint8_t *payload, const PropertyContext &ctx)
static void decode_context(PropertyContext &ctx, const uint8_t *payload)
static void encode(uint8_t *payload, uint8_t remote_temperature_half_deg, const PropertyContext &)
static void decode_context(PropertyContext &ctx, const uint8_t *payload)
static void decode(Status &status, const uint8_t *payload, const PropertyContext &ctx)
static void encode(uint8_t *payload, const Status &status, const PropertyContext &ctx)
static constexpr uint8_t TARGET_TEMPERATURE_ENC_A_OFFSET
static void decode_context(PropertyContext &ctx, const uint8_t *payload)
static void decode(Status &status, const uint8_t *payload, const PropertyContext &ctx)
static constexpr float decode(int temp_a, int temp_b, int delta)
static uint8_t decode_raw(const uint8_t *payload, const PropertyContext &ctx)
static constexpr auto MAP
static void encode_raw(uint8_t *payload, uint8_t raw, const PropertyContext &)
static void decode_context(PropertyContext &ctx, const uint8_t *payload)
static void encode_raw(uint8_t *payload, uint8_t raw, const PropertyContext &ctx)
static uint8_t decode_raw(const uint8_t *payload, const PropertyContext &ctx)
static constexpr auto MAP