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;
62 status.operating = payload[3] != 0;
68 static constexpr auto ID = PropertyId::TEMPERATURE;
82 payload[14] =
static_cast<uint8_t
>(std::round(
status.target_temperature * 2.0f) + 128);
98 static constexpr auto ID = PropertyId::REMOTE_TEMPERATURE;
105 payload[2] =
static_cast<uint8_t
>(remote_temperature_half_deg - 16);
106 payload[3] =
static_cast<uint8_t
>(remote_temperature_half_deg + 128);
112 static constexpr float decode(
int temp_a,
int temp_b,
int delta) {
113 return temp_b != 0 ? (temp_b - 128) / 2.0f : delta + temp_a;
117 template<
typename Derived, auto Field>
struct Lookup {
118 using Value = std::remove_cvref_t<decltype(std::declval<Status>().*Field)>;
123 status.*Field = Derived::MAP.lookup(Derived::decode_raw(payload, ctx));
128 if (Derived::MAP.reverse_lookup(
status.*Field,
raw)) {
129 Derived::encode_raw(payload,
raw, ctx);
135 if (!Derived::MAP.reverse_lookup(
value,
raw)) {
139 mask.set(Derived::ID);
145 constexpr Lookup() =
default;
149 static constexpr auto ID = PropertyId::MODE;
150 static constexpr auto MAP = make_map<MitsubishiCN105::Mode::UNKNOWN>({
163 const bool i_see = payload[3] > 0x08;
164 return payload[3] - (i_see ? 0x08 : 0);
174 static constexpr auto ID = PropertyId::FAN;
175 static constexpr auto MAP = make_map<MitsubishiCN105::FanMode::UNKNOWN>({
194 static constexpr auto ID = PropertyId::VANE;
195 static constexpr auto MAP = make_map<MitsubishiCN105::VaneMode::UNKNOWN>({
215 static constexpr auto ID = PropertyId::WIDE_VANE;
216 static constexpr auto MAP = make_map<MitsubishiCN105::WideVaneMode::UNKNOWN>({
250 if (this->payload.size() <= 10) {
258 if (this->payload.size() <= 5) {
266 if (this->payload.size() <= 3) {
274 template<
typename T,
typename Out> ESPHOME_ALWAYS_INLINE
void decode_one_(Out &
out) {
275 T::decode_context(this->context, this->payload.data());
276 if constexpr (
requires { T::ID; }) {
277 if (this->pending_writes.contains(T::ID)) {
281 T::decode(
out, this->payload.data(), this->context);
284 template<
typename... T,
typename Out>
void ESPHOME_ALWAYS_INLINE
decode_(Out &
out) {
295 this->payload[0] = 0x01;
300 this->payload[0] = 0x07;
305 template<
typename... T,
typename In>
void ESPHOME_ALWAYS_INLINE
encode_and_clear_(
const In &in) {
307 (this->pending_writes.clear(T::ID), ...);
310 template<
typename T,
typename In>
void encode_one_(
const In &in) {
311 if (this->pending_writes.contains(T::ID)) {
312 T::encode(this->payload, in, this->context);
static constexpr uint8_t REMOTE_TEMPERATURE_DISABLED
std::vector< uint8_t > & out
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)
bool ESPHOME_ALWAYS_INLINE decode_operating_status(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 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 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