Skip to content

Commit bf75ccf

Browse files
authored
Fix temp and reconnect (#16)
* fix: update .gitignore * feat: Add reconnect button functionality to Sharp AC component fix:temp --------- Co-authored-by: SvenH <[email protected]>
1 parent a72436b commit bf75ccf

File tree

8 files changed

+83
-6
lines changed

8 files changed

+83
-6
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Gitignore settings for ESPHome
2+
# Gitignore settings for ESPHome
23
/.esphome/
34
/secrets.yaml
45
/logs/
@@ -14,3 +15,12 @@ tests/*.o
1415
tests/test_frame_parsing
1516
tests/test_core_logic
1617
tests/test_integration
18+
wohnzimmer.yaml
19+
ota.yaml
20+
**/node_modules/
21+
22+
# C++ Unit Test artifacts
23+
tests/*.o
24+
tests/test_frame_parsing
25+
tests/test_core_logic
26+
tests/test_integration

components/sharp_ac/climate.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import esphome.codegen as cg
22
import esphome.config_validation as cv
3-
from esphome.components import climate, uart, select, switch, text_sensor
3+
from esphome.components import climate, uart, select, switch, text_sensor, button
44
from esphome.const import CONF_ID
55

6-
AUTO_LOAD = ["climate", "uart", "select", "switch", "text_sensor"]
6+
AUTO_LOAD = ["climate", "uart", "select", "switch", "text_sensor", "button"]
77
CODEOWNERS = ["@sven819"]
88

99
CONF_SHARP_ID = "sharp_id"
@@ -16,11 +16,13 @@
1616

1717
IonSwitch = sharp_ac_ns.class_("IonSwitch", switch.Switch)
1818
ConnectionStatusSensor = sharp_ac_ns.class_("ConnectionStatusSensor", text_sensor.TextSensor, cg.Component)
19+
ReconnectButton = sharp_ac_ns.class_("ReconnectButton", button.Button, cg.Component)
1920

2021
CONF_HORIZONTAL_SWING_SELECT = "horizontal_vane_select"
2122
CONF_VERTICAL_SWING_SELECT = "vertical_vane_select"
2223
CONF_ION_SWITCH = "ion_switch"
2324
CONF_CONNECTION_STATUS = "connection_status"
25+
CONF_RECONNECT_BUTTON = "reconnect_button"
2426

2527
HORIZONTAL_SWING_OPTIONS = ["swing","left","center","right"]
2628
VERTICAL_SWING_OPTIONS = ["auto", "swing" , "up" , "up_center", "center", "down_center", "down"]
@@ -45,13 +47,18 @@
4547
{cv.GenerateID(CONF_ID): cv.declare_id(ConnectionStatusSensor)}
4648
)
4749

50+
RECONNECT_BUTTON_SCHEMA = button.button_schema(ReconnectButton).extend(
51+
{cv.GenerateID(CONF_ID): cv.declare_id(ReconnectButton)}
52+
)
53+
4854
CONFIG_SCHEMA = climate.climate_schema(SharpAc).extend(
4955
{
5056
cv.GenerateID(): cv.declare_id(SharpAc),
5157
cv.Optional(CONF_HORIZONTAL_SWING_SELECT): SELECT_SCHEMA_HORIZONTAL,
5258
cv.Optional(CONF_VERTICAL_SWING_SELECT): SELECT_SCHEMA_VERTICAL,
5359
cv.Optional(CONF_ION_SWITCH): ION_SCHEMA,
54-
cv.Optional(CONF_CONNECTION_STATUS): CONNECTION_STATUS_SCHEMA
60+
cv.Optional(CONF_CONNECTION_STATUS): CONNECTION_STATUS_SCHEMA,
61+
cv.Optional(CONF_RECONNECT_BUTTON): RECONNECT_BUTTON_SCHEMA
5562
}
5663
).extend(uart.UART_DEVICE_SCHEMA)
5764

@@ -82,6 +89,13 @@ async def to_code(config):
8289
cg.add(var.setConnectionStatusSensor(sens))
8390
await cg.register_parented(sens, var)
8491

92+
if CONF_RECONNECT_BUTTON in config:
93+
conf = config[CONF_RECONNECT_BUTTON]
94+
btn = await button.new_button(conf)
95+
cg.add(btn.set_parent(var))
96+
cg.add(var.setReconnectButton(btn))
97+
await cg.register_parented(btn, var)
98+
8599
await uart.register_uart_device(var, config)
86100
await climate.register_climate(var, config)
87101
await cg.register_component(var, config)

components/sharp_ac/comp_hardware.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "comp_hardware.h"
22
#include "comp_vane_horizontal.h"
33
#include "comp_vane_vertical.h"
4+
#include "comp_reconnect_button.h"
45

56
namespace esphome
67
{
@@ -343,5 +344,23 @@ namespace esphome
343344
connectionStatusSensor->publish_state(status_text);
344345
}
345346

347+
void SharpAc::triggerReconnect()
348+
{
349+
ESP_LOGI("sharp_ac", "Triggering connection reset...");
350+
if (core_)
351+
{
352+
core_->resetConnection();
353+
}
354+
}
355+
356+
void ReconnectButton::press_action()
357+
{
358+
ESP_LOGI("sharp_ac", "Reconnect button pressed - resetting connection");
359+
if (this->parent_ != nullptr)
360+
{
361+
this->parent_->triggerReconnect();
362+
}
363+
}
364+
346365
}
347366
}

components/sharp_ac/comp_hardware.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "esphome/components/switch/switch.h"
66
#include "esphome/components/select/select.h"
77
#include "esphome/components/text_sensor/text_sensor.h"
8+
#include "esphome/components/button/button.h"
89
#include "esphome/core/log.h"
910
#include "esphome/core/helpers.h"
1011

@@ -32,6 +33,7 @@ namespace esphome
3233
class VaneSelectVertical;
3334
class VaneSelectHorizontal;
3435
class ConnectionStatusSensor;
36+
class ReconnectButton;
3537
class SharpAc;
3638

3739
class ESPHomeHardwareInterface : public SharpAcHardwareInterface {
@@ -124,7 +126,13 @@ namespace esphome
124126
this->connectionStatusSensor = sensor;
125127
};
126128

129+
void setReconnectButton(button::Button *button)
130+
{
131+
this->reconnectButton = button;
132+
};
133+
127134
void updateConnectionStatus(int status);
135+
void triggerReconnect();
128136

129137
private:
130138
std::unique_ptr<ESPHomeHardwareInterface> hardware_interface_;
@@ -135,6 +143,7 @@ namespace esphome
135143
VaneSelectVertical *vaneVertical;
136144
VaneSelectHorizontal *vaneHorizontal;
137145
text_sensor::TextSensor *connectionStatusSensor{nullptr};
146+
button::Button *reconnectButton{nullptr};
138147
};
139148
}
140149
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
#include "esphome/components/button/button.h"
4+
#include "esphome/core/component.h"
5+
6+
namespace esphome
7+
{
8+
namespace sharp_ac
9+
{
10+
class SharpAc;
11+
12+
class ReconnectButton : public button::Button, public Component
13+
{
14+
public:
15+
void set_parent(SharpAc *parent) { this->parent_ = parent; }
16+
17+
protected:
18+
void press_action() override;
19+
SharpAc *parent_{nullptr};
20+
};
21+
22+
}
23+
}

components/sharp_ac/core_frame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ SharpStatusFrame::SharpStatusFrame(const uint8_t *arr) : SharpFrame(arr, 18)
8282

8383
int SharpStatusFrame::getTemperature()
8484
{
85-
return (this->data[7] & 0x0F) + 16;
85+
return this->data[7];
8686
}
8787

8888
SharpModeFrame::SharpModeFrame(const uint8_t *arr) : SharpFrame(arr, 14)

components/sharp_ac/core_logic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ namespace esphome
6060
void controlSwing(SwingHorizontal h, SwingVertical v);
6161
void controlTemperature(int temperature);
6262
void controlPreset(Preset preset);
63+
void resetConnection();
6364

6465
protected:
6566
std::string analyzeByte(uint8_t byte, size_t position, bool isStatusFrame);
@@ -96,7 +97,6 @@ namespace esphome
9697
void processUpdate(SharpFrame &frame);
9798
void startInit();
9899
void checkTimeout();
99-
void resetConnection();
100100
int status = 0;
101101
unsigned long connectionStart = 0;
102102
unsigned long previousMillis = 0;

klima.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ climate:
4040
ion_switch:
4141
name: Plasmacluster
4242
connection_status:
43-
name: "AC Connection Status"
43+
name: "AC Connection Status"
44+
reconnect_button:
45+
name: "AC Reconnect"

0 commit comments

Comments
 (0)