Skip to content

Commit

Permalink
Added working version
Browse files Browse the repository at this point in the history
  • Loading branch information
muxa committed Aug 20, 2022
1 parent 4c3cc4d commit 2b3fc3d
Show file tree
Hide file tree
Showing 9 changed files with 1,361 additions and 0 deletions.
137 changes: 137 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
Language: Cpp
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: DontAlign
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 2000
PointerAlignment: Right
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
CanonicalDelimiter: ''
BasedOnStyle: google
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: false
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 2
UseTab: Never
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,34 @@
ESPHome component to integrate with Toshiba Air Conditioners via TCC-Link protocol (AB line).

Requires reader & writer circuit for the AB line: https://github.com/issalig/toshiba_air_cond

## Install

```yaml
external_components:
- source:
type: git
url: https://github.com/muxa/esphome-tcc-link

```

## Usage

```yaml
uart:
tx_pin: GPIO1
rx_pin: GPIO3
baud_rate: 2400
parity: EVEN

climate:
- platform: tcc_link
name: "Toshiba AC"
id: toshiba_ac
connected:
name: "Toshiba AC Connected"
failed_crcs:
name: "Toshiba AC Failed CRCs"
vent:
name: "Toshiba AC Vent Switch"
```
Empty file added components/tcc_link/__init__.py
Empty file.
26 changes: 26 additions & 0 deletions components/tcc_link/automation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include "esphome/core/component.h"
#include "esphome/core/automation.h"
#include "tcc_link.h"

namespace esphome
{
namespace tcc_link
{

class TccLinkOnDataReceivedTrigger : public Trigger<std::vector<uint8_t>>
{
public:
TccLinkOnDataReceivedTrigger(TccLinkClimate *climate)
{
climate->add_on_data_received_callback(
[this](const struct DataFrame *frame)
{
this->trigger(frame->get_data());
});
}
};

} // namespace tcc_link
} // namespace esphome
108 changes: 108 additions & 0 deletions components/tcc_link/climate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import automation
from esphome.components import climate, uart, binary_sensor, sensor, switch, text_sensor, template
from esphome.const import (
CONF_ID,
CONF_NAME,
CONF_HARDWARE_UART,
CONF_BAUD_RATE,
CONF_UPDATE_INTERVAL,
CONF_MODE,
CONF_FAN_MODE,
CONF_SWING_MODE,
CONF_TRIGGER_ID,
DEVICE_CLASS_CONNECTIVITY,
ENTITY_CATEGORY_DIAGNOSTIC,
STATE_CLASS_MEASUREMENT,
)

DEPENDENCIES = ["uart"]
AUTO_LOAD = ["climate", "binary_sensor", "sensor", "switch"]
CODEOWNERS = ["@muxa"]

tcc_link_ns = cg.esphome_ns.namespace("tcc_link")

CONF_CONNECTED = "connected"
CONF_VENT = "vent"
CONF_FAILED_CRCS = "failed_crcs"

CONF_ON_DATA_RECEIVED = "on_data_received"

TccLinkClimate = tcc_link_ns.class_(
"TccLinkClimate", climate.Climate, uart.UARTDevice, cg.Component
)

TccLinkVentSwitch = tcc_link_ns.class_(
"TccLinkVentSwitch", switch.Switch, cg.Component
)

TccLinkOnDataReceivedTrigger = tcc_link_ns.class_(
"TccLinkOnDataReceivedTrigger", automation.Trigger.template()
)

CONFIG_SCHEMA = climate.CLIMATE_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(TccLinkClimate),
cv.Optional(CONF_CONNECTED): binary_sensor.binary_sensor_schema(
device_class = DEVICE_CLASS_CONNECTIVITY,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
cv.Optional(CONF_VENT): cv.maybe_simple_value(
switch.SWITCH_SCHEMA.extend(
cv.Schema(
{
cv.GenerateID(): cv.declare_id(TccLinkVentSwitch),
}
)
),
key=CONF_NAME,
),
cv.Optional(CONF_FAILED_CRCS): sensor.sensor_schema(
accuracy_decimals=0,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
state_class=STATE_CLASS_MEASUREMENT,
),
cv.Optional(CONF_ON_DATA_RECEIVED): automation.validate_automation(
{
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
TccLinkOnDataReceivedTrigger
),
}
),
}
).extend(uart.UART_DEVICE_SCHEMA).extend(cv.COMPONENT_SCHEMA)

def validate_uart(config):
uart.final_validate_device_schema(
"tcc_link", baud_rate=2400, require_rx=True, require_tx=False
)(config)


FINAL_VALIDATE_SCHEMA = validate_uart

async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])

await cg.register_component(var, config)
await climate.register_climate(var, config)
await uart.register_uart_device(var, config)

if CONF_CONNECTED in config:
sens = await binary_sensor.new_binary_sensor(config[CONF_CONNECTED])
cg.add(var.set_connected_binary_sensor(sens))

if CONF_FAILED_CRCS in config:
sens = await sensor.new_sensor(config[CONF_FAILED_CRCS])
cg.add(var.set_failed_crcs_sensor(sens))

if CONF_VENT in config:
sw = await switch.new_switch(config[CONF_VENT], var)
cg.add(var.set_vent_switch(sw))

if CONF_ON_DATA_RECEIVED in config:
for on_data_received in config.get(CONF_ON_DATA_RECEIVED, []):
data_trigger = cg.new_Pvariable(on_data_received[CONF_TRIGGER_ID], var)
await automation.build_automation(
data_trigger, [(cg.std_vector.template(cg.uint8), "x")], on_data_received
)
Loading

0 comments on commit 2b3fc3d

Please sign in to comment.