Skip to content

Commit

Permalink
Merge pull request #23 from lorenzo-deluca/hotfix/specific-area-disar…
Browse files Browse the repository at this point in the history
…m-issue

Hotfix/specific area disarm issue
  • Loading branch information
lorenzo-deluca authored Aug 5, 2022
2 parents 2f54de6 + 88bb4ec commit 2f02d1b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@ service: esphome.espkyogate_arm_area
data:
arm_type: 1 (total arm) - 2 (partially arm)
area: <area_number>
specific_area: 1 (arm <area_number> and disarm others) - 0 (arm only <area_number> without changing the others)
specific_area: 1 (arm only <area_number> without changing the others) - 0 (arm only <area_number> and disarm others)
```

### Area Disarm
``` yaml
service: esphome.espkyogate_disarm_area
data:
area: <area_number>
specific_area: 1 (disarm all areas) - 0 (disarm only <area_number> without changing the others)
specific_area: 0 (disarm all areas) - 1 (disarm only <area_number> without changing the others)
```

### Reset Alarm Memory
Expand Down Expand Up @@ -269,7 +269,8 @@ Ff you have any problems, make the following checks:
* Check that the cables are connected correctly
* Check the 232 converter is properly powered
* Try to reverse TX and RX
* Verify that the central unit has firmware **2.13**
* Verify that the central unit has firmware **2.13**, if it isn't you've to update central unit firmware to this version.


### Diagnostics Service
For diagnostics you can enable additional software logs through this service.
Expand All @@ -280,7 +281,11 @@ service: esphome.espkyogate_debug_command
data:
serial_trace: 1
log_trace: 1
polling_kyo: 1
```
* **serial_trace** Enable or Disable Serial Log communication to central unit
* **log_trace** Enable or Disable Application Log
* **polling_kyo** Enable or Disable continuative polling to central unit (default always Enable)

## License
GNU AGPLv3 © [Lorenzo De Luca][https://lorenzodeluca.dev]
32 changes: 16 additions & 16 deletions bentel-kyo/bentel_kyo32.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Bentel_Kyo32 : public esphome::PollingComponent, public uart::UARTDevice,
return;
}

ESP_LOGI("arm_area", "request arm type %d area %d", arm_type, area);
ESP_LOGI("arm_area", "request arm type %d area %d specific %d", arm_type, area, specific_area);
byte cmdArmPartition[11] = {0x0F, 0x00, 0xF0, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0xCC, 0xFF};

byte total_insert_area_status = 0x00, partial_insert_area_status = 0x00;
Expand All @@ -106,19 +106,19 @@ class Bentel_Kyo32 : public esphome::PollingComponent, public uart::UARTDevice,
cmdArmPartition[9] = calculateCRC(cmdArmPartition, 8);

byte Rx[255];
int Count = sendMessageToKyo(cmdArmPartition, sizeof(cmdArmPartition), Rx, 100);
int Count = sendMessageToKyo(cmdArmPartition, sizeof(cmdArmPartition), Rx, 250);
ESP_LOGD("arm_area", "arm_area kyo respond %i", Count);
}

void disarm_area(int area, int specific_area)
{
if (area > KYO_MAX_AREE)
{
ESP_LOGE("arm_area", "invalid Area %i, MAX %i", area, KYO_MAX_AREE);
ESP_LOGE("disarm_area", "invalid area %i, MAX %i", area, KYO_MAX_AREE);
return;
}

ESP_LOGI("disarm_area", "request disarm area %d", area);
ESP_LOGI("disarm_area", "request disarm area %d , specific %d", area, specific_area);
byte cmdDisarmPartition[11] = {0x0F, 0x00, 0xF0, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0xFF, 0xFF};

byte total_insert_area_status = 0x00, partial_insert_area_status = 0x00;
Expand All @@ -132,17 +132,17 @@ class Bentel_Kyo32 : public esphome::PollingComponent, public uart::UARTDevice,
}

if (this->inserimento_totale_area[area - 1].state)
total_insert_area_status |= 0 << (area - 1);
total_insert_area_status &= ~(1 << (area - 1));
else
partial_insert_area_status |= 1 << (area - 1);
partial_insert_area_status &= ~(1 << (area - 1));
}

cmdDisarmPartition[6] = total_insert_area_status;
cmdDisarmPartition[7] = partial_insert_area_status;
cmdDisarmPartition[9] = calculateCRC(cmdDisarmPartition, 8);

byte Rx[255];
int Count = sendMessageToKyo(cmdDisarmPartition, sizeof(cmdDisarmPartition), Rx, 80);
int Count = sendMessageToKyo(cmdDisarmPartition, sizeof(cmdDisarmPartition), Rx, 100);
ESP_LOGD("disarm_area", "kyo respond %i", Count);
}

Expand All @@ -151,7 +151,7 @@ class Bentel_Kyo32 : public esphome::PollingComponent, public uart::UARTDevice,
ESP_LOGI("reset_alarms", "Reset Alarms.");

byte Rx[255];
int Count = sendMessageToKyo(cmdResetAllarms, sizeof(cmdResetAllarms), Rx, 80);
int Count = sendMessageToKyo(cmdResetAllarms, sizeof(cmdResetAllarms), Rx, 250);
ESP_LOGE("reset_alarms", "kyo respond %i", Count);
}

Expand Down Expand Up @@ -180,7 +180,7 @@ class Bentel_Kyo32 : public esphome::PollingComponent, public uart::UARTDevice,
cmdActivateOutput[8] = cmdActivateOutput[6];

byte Rx[255];
int Count = sendMessageToKyo(cmdActivateOutput, sizeof(cmdActivateOutput), Rx, 80);
int Count = sendMessageToKyo(cmdActivateOutput, sizeof(cmdActivateOutput), Rx, 250);
ESP_LOGD("activate_output", "kyo respond %i", Count);
}

Expand All @@ -200,7 +200,7 @@ class Bentel_Kyo32 : public esphome::PollingComponent, public uart::UARTDevice,
cmdDeactivateOutput[8] = cmdDeactivateOutput[7];

byte Rx[255];
int Count = sendMessageToKyo(cmdDeactivateOutput, sizeof(cmdDeactivateOutput), Rx, 80);
int Count = sendMessageToKyo(cmdDeactivateOutput, sizeof(cmdDeactivateOutput), Rx, 250);
ESP_LOGD("deactivate_output", "kyo respond %i", Count);
}

Expand All @@ -226,7 +226,7 @@ class Bentel_Kyo32 : public esphome::PollingComponent, public uart::UARTDevice,
cmdUpdateDateTime[12] = getChecksum(cmdUpdateDateTime, 6, 12);

byte Rx[255];
int Count = sendMessageToKyo(cmdUpdateDateTime, sizeof(cmdUpdateDateTime), Rx, 200);
int Count = sendMessageToKyo(cmdUpdateDateTime, sizeof(cmdUpdateDateTime), Rx, 300);
ESP_LOGD("update_datetime", "kyo respond %i", Count);
}

Expand Down Expand Up @@ -298,7 +298,7 @@ class Bentel_Kyo32 : public esphome::PollingComponent, public uart::UARTDevice,
byte Rx[255];
int Count = 0;

Count = sendMessageToKyo(cmdGetPartitionStatus, sizeof(cmdGetPartitionStatus), Rx, 100);
Count = sendMessageToKyo(cmdGetPartitionStatus, sizeof(cmdGetPartitionStatus), Rx);
if (Count != 26)
{
if (this->logTrace)
Expand Down Expand Up @@ -434,7 +434,7 @@ class Bentel_Kyo32 : public esphome::PollingComponent, public uart::UARTDevice,
byte Rx[255];
int Count = 0;

Count = sendMessageToKyo(cmdGetSensorStatus, sizeof(cmdGetSensorStatus), Rx, 100);
Count = sendMessageToKyo(cmdGetSensorStatus, sizeof(cmdGetSensorStatus), Rx);
if (Count != 18)
{
if (this->logTrace)
Expand Down Expand Up @@ -558,7 +558,7 @@ class Bentel_Kyo32 : public esphome::PollingComponent, public uart::UARTDevice,
return true;
}

int sendMessageToKyo(byte *cmd, int lcmd, byte ReadByes[], int waitForAnswer = 0)
int sendMessageToKyo(byte *cmd, int lcmd, byte ReadByes[], int waitForAnswer = 100)
{
// clean rx buffer
while (available() > 0)
Expand All @@ -575,7 +575,7 @@ class Bentel_Kyo32 : public esphome::PollingComponent, public uart::UARTDevice,
while (available() > 0)
RxBuff[index++] = read();

if (this->serialTrace)
if (this->serialTrace || waitForAnswer > 100)
ESP_LOGI("sendMessageToKyo", "TX '%s'", format_hex_pretty(cmd, lcmd).c_str());

if (index <= 0)
Expand All @@ -584,7 +584,7 @@ class Bentel_Kyo32 : public esphome::PollingComponent, public uart::UARTDevice,
return -1;
}

if (this->serialTrace)
if (this->serialTrace || waitForAnswer > 100)
ESP_LOGI("sendMessageToKyo", "RX '%s'", format_hex_pretty(RxBuff, index).c_str());

memcpy(ReadByes, RxBuff, index);
Expand Down

0 comments on commit 2f02d1b

Please sign in to comment.