Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NASA] Add target water temperature #95

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions components/samsung_ac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
CONF_DEVICE_CLIMATE = "climate"
CONF_DEVICE_ROOM_HUMIDITY = "room_humidity"
CONF_DEVICE_WATER_TEMPERATURE = "water_temperature"
CONF_DEVICE_WATER_TARGET_TEMPERATURE = "water_target_temperature"
CONF_DEVICE_CUSTOM = "custom_sensor"
CONF_DEVICE_CUSTOM_MESSAGE = "message"
CONF_DEVICE_CUSTOM_RAW_FILTERS = "raw_filters"
Expand Down Expand Up @@ -177,6 +178,7 @@ def humidity_sensor_schema(message: int):
state_class=STATE_CLASS_MEASUREMENT,
),
cv.Optional(CONF_DEVICE_TARGET_TEMPERATURE): NUMBER_SCHEMA,
cv.Optional(CONF_DEVICE_WATER_TARGET_TEMPERATURE): NUMBER_SCHEMA,
cv.Optional(CONF_DEVICE_POWER): switch.switch_schema(Samsung_AC_Switch),
cv.Optional(CONF_DEVICE_MODE): SELECT_MODE_SCHEMA,
cv.Optional(CONF_DEVICE_CLIMATE): CLIMATE_SCHEMA,
Expand Down Expand Up @@ -295,6 +297,16 @@ async def to_code(config):
cg.add(var_dev.set_room_temperature_offset(
device[CONF_DEVICE_ROOM_TEMPERATURE_OFFSET]))

if CONF_DEVICE_WATER_TARGET_TEMPERATURE in device:
conf = device[CONF_DEVICE_WATER_TARGET_TEMPERATURE]
conf[CONF_UNIT_OF_MEASUREMENT] = UNIT_CELSIUS
conf[CONF_DEVICE_CLASS] = DEVICE_CLASS_TEMPERATURE
num = await number.new_number(conf,
min_value=10.0,
max_value=60.0,
step=0.5)
cg.add(var_dev.set_target_water_temperature_number(num))

if CONF_DEVICE_OUTDOOR_TEMPERATURE in device:
conf = device[CONF_DEVICE_OUTDOOR_TEMPERATURE]
sens = await sensor.new_sensor(conf)
Expand Down
4 changes: 3 additions & 1 deletion components/samsung_ac/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ namespace esphome
virtual void set_power(const std::string address, bool value) = 0;
virtual void set_room_temperature(const std::string address, float value) = 0;
virtual void set_target_temperature(const std::string address, float value) = 0;
virtual void set_target_water_temperature(const std::string address, float value) = 0;
virtual void set_outdoor_temperature(const std::string address, float value) = 0;
virtual void set_mode(const std::string address, Mode mode) = 0;
virtual void set_fanmode(const std::string address, FanMode fanmode) = 0;
Expand All @@ -84,6 +85,7 @@ namespace esphome
optional<bool> power;
optional<Mode> mode;
optional<float> target_temp;
optional<float> target_water_temp;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You added the water temperature to the request, but you did not extended the code witch sents the request.

Please also add a not supported message to non_nasa code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😬 I'm not sure where to add the "not supported message to non_nasa code" -- can you link to an example ?
same for water temp

optional<FanMode> fan_mode;
optional<SwingMode> swing_mode;
optional<AltMode> alt_mode;
Expand Down Expand Up @@ -117,4 +119,4 @@ namespace esphome
AddressType get_address_type(const std::string &address);

} // namespace samsung_ac
} // namespace esphome
} // namespace esphome
7 changes: 7 additions & 0 deletions components/samsung_ac/protocol_nasa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,13 @@ namespace esphome
ESP_LOGW(TAG, "s:%s d:%s NASA_OUTDOOR_CONTROL_WATTMETER_TOTAL_SUM_ACCUM %f", source.c_str(), dest.c_str(), value);
return;
}
if ((uint16_t)message.messageNumber == MessageNumber::VAR_in_temp_water_heater_target_f)
{ // VAR WATER_TARGET_TEMP
double temp = (double)message.value / (double)10;
ESP_LOGW(TAG, "s:%s d:%s VAR WATER_TARGET_TEMP %li", source.c_str(), dest.c_str(), message.value);
target->set_target_water_temperature(source, temp);
return;
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions components/samsung_ac/protocol_nasa.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ namespace esphome
ENUM_in_state_humidity_percent = 0x4038,
VAR_in_temp_room_f = 0x4203,
VAR_in_temp_target_f = 0x4201,
VAR_in_temp_water_heater_target_f = 0x4235,
VAR_in_temp_water_tank_f = 0x4237,
VAR_out_sensor_airout = 0x8204,
};
Expand Down
7 changes: 7 additions & 0 deletions components/samsung_ac/samsung_ac.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ namespace esphome
dev->update_target_temperature(value);
}

void /*MessageTarget::*/ set_target_water_temperature(const std::string address, float value) override
{
Samsung_AC_Device *dev = find_device(address);
if (dev != nullptr)
dev->update_target_water_temperature(value);
}

void /*MessageTarget::*/ set_power(const std::string address, bool value) override
{
Samsung_AC_Device *dev = find_device(address);
Expand Down
18 changes: 18 additions & 0 deletions components/samsung_ac/samsung_ac_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ namespace esphome
sensor::Sensor *room_temperature{nullptr};
sensor::Sensor *outdoor_temperature{nullptr};
Samsung_AC_Number *target_temperature{nullptr};
Samsung_AC_Number *target_water_temperature{nullptr};
Samsung_AC_Switch *power{nullptr};
Samsung_AC_Mode_Select *mode{nullptr};
Samsung_AC_Climate *climate{nullptr};
Expand Down Expand Up @@ -155,6 +156,17 @@ namespace esphome
};
};

void set_target_water_temperature_number(Samsung_AC_Number *number)
{
target_water_temperature = number;
target_water_temperature->write_state_ = [this](float value)
{
ProtocolRequest request;
request.target_water_temp = value;
publish_request(request);
};
};

void set_climate(Samsung_AC_Climate *value)
{
climate = value;
Expand All @@ -172,6 +184,12 @@ namespace esphome
}
}

void update_target_water_temperature(float value)
{
if (target_water_temperature != nullptr)
target_water_temperature->publish_state(value);
}

optional<bool> _cur_power;
optional<Mode> _cur_mode;

Expand Down
9 changes: 9 additions & 0 deletions test/test_stuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ class DebugTarget : public MessageTarget
last_set_target_temperature_value = value;
}

std::string last_set_target_water_temperature_address;
float last_set_target_water_temperature_value;
void set_target_water_temperature(const std::string address, float value)
{
cout << "> " << address << " set_target_water_temperature=" << to_string(value) << endl;
last_set_target_water_temperature_address = address;
last_set_target_water_temperature_value = value;
}

std::string last_set_outdoor_temperature_address;
float last_set_outdoor_temperature_value;
void set_outdoor_temperature(const std::string address, float value)
Expand Down