-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
539 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: true | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import esphome.codegen as cg | ||
import esphome.config_validation as cv | ||
from esphome.components import sensor, esp32_ble_tracker | ||
from esphome import automation | ||
from esphome.const import ( | ||
CONF_MAC_ADDRESS, | ||
CONF_BINDKEY, | ||
UNIT_EMPTY, | ||
ICON_EMPTY, | ||
DEVICE_CLASS_EMPTY, | ||
CONF_ID, | ||
CONF_TRIGGER_ID, | ||
) | ||
|
||
AUTO_LOAD = ["xiaomi_ble", "sensor"] | ||
CODEOWNERS = ["@syssi"] | ||
DEPENDENCIES = ["esp32_ble_tracker"] | ||
MULTI_CONF = True | ||
|
||
CONF_LAST_BUTTON_PRESSED = "last_button_pressed" | ||
CONF_ON_BUTTON_ON = "on_button_on" | ||
|
||
ON_PRESS_ACTIONS = [ | ||
CONF_ON_BUTTON_ON, | ||
] | ||
|
||
xiaomi_ylkg07yl_ns = cg.esphome_ns.namespace("xiaomi_ylkg07yl") | ||
XiaomiYLKG07YL = xiaomi_ylkg07yl_ns.class_( | ||
"XiaomiYLKG07YL", esp32_ble_tracker.ESPBTDeviceListener, cg.Component | ||
) | ||
|
||
OnButtonOnTrigger = xiaomi_ylkg07yl_ns.class_( | ||
"OnButtonOnTrigger", automation.Trigger.template() | ||
) | ||
|
||
|
||
def validate_short_bind_key(value): | ||
value = cv.string_strict(value) | ||
parts = [value[i : i + 2] for i in range(0, len(value), 2)] | ||
if len(parts) != 12: | ||
raise cv.Invalid("Bind key must consist of 12 hexadecimal numbers") | ||
parts_int = [] | ||
if any(len(part) != 2 for part in parts): | ||
raise cv.Invalid("Bind key must be format XX") | ||
for part in parts: | ||
try: | ||
parts_int.append(int(part, 16)) | ||
except ValueError: | ||
# pylint: disable=raise-missing-from | ||
raise cv.Invalid("Bind key must be hex values from 00 to FF") | ||
|
||
return "".join(f"{part:02X}" for part in parts_int) | ||
|
||
|
||
CONFIG_SCHEMA = ( | ||
cv.Schema( | ||
{ | ||
cv.GenerateID(): cv.declare_id(XiaomiYLKG07YL), | ||
cv.Required(CONF_MAC_ADDRESS): cv.mac_address, | ||
cv.Required(CONF_BINDKEY): validate_short_bind_key, | ||
cv.Optional(CONF_LAST_BUTTON_PRESSED): sensor.sensor_schema( | ||
UNIT_EMPTY, ICON_EMPTY, 1, DEVICE_CLASS_EMPTY | ||
), | ||
cv.Optional(CONF_ON_BUTTON_ON): automation.validate_automation( | ||
{ | ||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(OnButtonOnTrigger), | ||
} | ||
), | ||
} | ||
) | ||
.extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA) | ||
.extend(cv.COMPONENT_SCHEMA) | ||
) | ||
|
||
|
||
async def to_code(config): | ||
var = cg.new_Pvariable(config[CONF_ID]) | ||
await cg.register_component(var, config) | ||
await esp32_ble_tracker.register_ble_device(var, config) | ||
|
||
cg.add(var.set_address(config[CONF_MAC_ADDRESS].as_hex)) | ||
cg.add(var.set_bindkey(config[CONF_BINDKEY])) | ||
|
||
if CONF_LAST_BUTTON_PRESSED in config: | ||
sens = await sensor.new_sensor(config[CONF_LAST_BUTTON_PRESSED]) | ||
cg.add(var.set_keycode(sens)) | ||
|
||
for action in ON_PRESS_ACTIONS: | ||
for conf in config.get(action, []): | ||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var) | ||
await automation.build_automation(trigger, [], conf) |
Oops, something went wrong.