mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
fix dallas sensor checking
This commit is contained in:
@@ -235,7 +235,7 @@ const DashboardData: FC = () => {
|
|||||||
iconDown: <KeyboardArrowDownOutlinedIcon />
|
iconDown: <KeyboardArrowDownOutlinedIcon />
|
||||||
},
|
},
|
||||||
sortFns: {
|
sortFns: {
|
||||||
GPIO: (array) => array.sort((a, b) => a.i - b.i),
|
GPIO: (array) => array.sort((a, b) => a.g - b.g),
|
||||||
NAME: (array) => array.sort((a, b) => a.n.localeCompare(b.n)),
|
NAME: (array) => array.sort((a, b) => a.n.localeCompare(b.n)),
|
||||||
TYPE: (array) => array.sort((a, b) => a.t - b.t),
|
TYPE: (array) => array.sort((a, b) => a.t - b.t),
|
||||||
VALUE: (array) => array.sort((a, b) => a.v.toString().localeCompare(b.v.toString()))
|
VALUE: (array) => array.sort((a, b) => a.v.toString().localeCompare(b.v.toString()))
|
||||||
@@ -531,7 +531,7 @@ const DashboardData: FC = () => {
|
|||||||
if (sensor) {
|
if (sensor) {
|
||||||
try {
|
try {
|
||||||
const response = await EMSESP.writeSensor({
|
const response = await EMSESP.writeSensor({
|
||||||
id_str: sensor.id,
|
id: sensor.id,
|
||||||
name: sensor.n,
|
name: sensor.n,
|
||||||
offset: sensor.o
|
offset: sensor.o
|
||||||
});
|
});
|
||||||
@@ -926,7 +926,7 @@ const DashboardData: FC = () => {
|
|||||||
<Body>
|
<Body>
|
||||||
{tableList.map((a: Analog) => (
|
{tableList.map((a: Analog) => (
|
||||||
<Row key={a.id} item={a} onClick={() => updateAnalog(a)}>
|
<Row key={a.id} item={a} onClick={() => updateAnalog(a)}>
|
||||||
<Cell>{a.id}</Cell>
|
<Cell>{a.g}</Cell>
|
||||||
<Cell>{a.n}</Cell>
|
<Cell>{a.n}</Cell>
|
||||||
<Cell>{AnalogTypeNames[a.t]} </Cell>
|
<Cell>{AnalogTypeNames[a.t]} </Cell>
|
||||||
<Cell>{a.t ? formatValue(a.v, a.u) : ''}</Cell>
|
<Cell>{a.t ? formatValue(a.v, a.u) : ''}</Cell>
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ export interface Analog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface WriteSensor {
|
export interface WriteSensor {
|
||||||
id_str: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
offset: number;
|
offset: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -972,7 +972,7 @@ rest_server.post(EMSESP_WRITE_VALUE_ENDPOINT, (req, res) => {
|
|||||||
rest_server.post(EMSESP_WRITE_SENSOR_ENDPOINT, (req, res) => {
|
rest_server.post(EMSESP_WRITE_SENSOR_ENDPOINT, (req, res) => {
|
||||||
const sensor = req.body
|
const sensor = req.body
|
||||||
console.log('Write sensor: ' + JSON.stringify(sensor))
|
console.log('Write sensor: ' + JSON.stringify(sensor))
|
||||||
objIndex = emsesp_sensordata.sensors.findIndex((obj) => obj.id == sensor.id_str)
|
objIndex = emsesp_sensordata.sensors.findIndex((obj) => obj.id == sensor.id)
|
||||||
emsesp_sensordata.sensors[objIndex].n = sensor.name
|
emsesp_sensordata.sensors[objIndex].n = sensor.name
|
||||||
emsesp_sensordata.sensors[objIndex].o = sensor.offset
|
emsesp_sensordata.sensors[objIndex].o = sensor.offset
|
||||||
res.sendStatus(200)
|
res.sendStatus(200)
|
||||||
|
|||||||
@@ -503,15 +503,15 @@ DallasSensor::Sensor::Sensor(const uint8_t addr[])
|
|||||||
: internal_id_(((uint64_t)addr[0] << 48) | ((uint64_t)addr[1] << 40) | ((uint64_t)addr[2] << 32) | ((uint64_t)addr[3] << 24) | ((uint64_t)addr[4] << 16)
|
: internal_id_(((uint64_t)addr[0] << 48) | ((uint64_t)addr[1] << 40) | ((uint64_t)addr[2] << 32) | ((uint64_t)addr[3] << 24) | ((uint64_t)addr[4] << 16)
|
||||||
| ((uint64_t)addr[5] << 8) | ((uint64_t)addr[6])) {
|
| ((uint64_t)addr[5] << 8) | ((uint64_t)addr[6])) {
|
||||||
// create ID string
|
// create ID string
|
||||||
char id_str[20];
|
char id_s[20];
|
||||||
snprintf(id_str,
|
snprintf(id_s,
|
||||||
sizeof(id_str),
|
sizeof(id_s),
|
||||||
"%02X-%04X-%04X-%04X",
|
"%02X-%04X-%04X-%04X",
|
||||||
(unsigned int)(internal_id_ >> 48) & 0xFF,
|
(unsigned int)(internal_id_ >> 48) & 0xFF,
|
||||||
(unsigned int)(internal_id_ >> 32) & 0xFFFF,
|
(unsigned int)(internal_id_ >> 32) & 0xFFFF,
|
||||||
(unsigned int)(internal_id_ >> 16) & 0xFFFF,
|
(unsigned int)(internal_id_ >> 16) & 0xFFFF,
|
||||||
(unsigned int)(internal_id_)&0xFFFF);
|
(unsigned int)(internal_id_)&0xFFFF);
|
||||||
id_ = std::string(id_str);
|
id_ = std::string(id_s);
|
||||||
name_ = std::string{}; // name (alias) is empty
|
name_ = std::string{}; // name (alias) is empty
|
||||||
offset_ = 0; // 0 degrees offset
|
offset_ = 0; // 0 degrees offset
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ class DallasSensor {
|
|||||||
bool temperature_convert_complete();
|
bool temperature_convert_complete();
|
||||||
int16_t get_temperature_c(const uint8_t addr[]);
|
int16_t get_temperature_c(const uint8_t addr[]);
|
||||||
uint64_t get_id(const uint8_t addr[]);
|
uint64_t get_id(const uint8_t addr[]);
|
||||||
void remove_ha_topic(const std::string & id_str);
|
void remove_ha_topic(const std::string & id);
|
||||||
|
|
||||||
bool command_info(const char * value, const int8_t id, JsonObject & output);
|
bool command_info(const char * value, const int8_t id, JsonObject & output);
|
||||||
bool command_commands(const char * value, const int8_t id, JsonObject & output);
|
bool command_commands(const char * value, const int8_t id, JsonObject & output);
|
||||||
|
|||||||
@@ -550,6 +550,11 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
|||||||
|
|
||||||
if (command == "dallas") {
|
if (command == "dallas") {
|
||||||
shell.printfln(F("Testing adding Dallas sensor"));
|
shell.printfln(F("Testing adding Dallas sensor"));
|
||||||
|
emsesp::EMSESP::dallassensor_.test();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command == "dallas_full") {
|
||||||
|
shell.printfln(F("Testing adding and changing Dallas sensor"));
|
||||||
Mqtt::ha_enabled(true);
|
Mqtt::ha_enabled(true);
|
||||||
Mqtt::nested_format(1);
|
Mqtt::nested_format(1);
|
||||||
// Mqtt::nested_format(0);
|
// Mqtt::nested_format(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user