-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
81 additions
and
10 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
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 |
---|---|---|
@@ -1,6 +1,44 @@ | ||
from core.integration.state import StateIntegration | ||
from typing import Optional | ||
|
||
from appdaemon.plugins.hass.hassapi import Hass # type: ignore | ||
from appdaemon.plugins.mqtt.mqttapi import Mqtt # type: ignore | ||
|
||
class Z2MIntegration(StateIntegration): | ||
from const import TypeActionsMapping | ||
from core.integration import Integration | ||
|
||
STATE_HA = "ha" | ||
STATE_MQTT = "mqtt" | ||
|
||
|
||
class Z2MIntegration(Integration): | ||
def get_name(self) -> str: | ||
return "z2m" | ||
|
||
def get_actions_mapping(self) -> Optional[TypeActionsMapping]: | ||
return self.controller.get_z2m_actions_mapping() | ||
|
||
def listen_changes(self, controller_id: str) -> None: | ||
state = self.kwargs.get("state", "ha") | ||
if state == STATE_HA: | ||
Hass.listen_state(self.controller, self.state_callback, controller_id) | ||
elif state == STATE_MQTT: | ||
Mqtt.listen_event( | ||
self.controller, | ||
self.event_callback, | ||
"MQTT_MESSAGE", | ||
topic=controller_id, | ||
) | ||
else: | ||
self.controller.log( | ||
f"Option `{state}` does not exists for `state` attribute. " | ||
'Options are: ["ha", "mqtt"]', | ||
level="WARNING", | ||
) | ||
|
||
async def event_callback(self, event_name: str, data: dict, kwargs: dict) -> None: | ||
pass | ||
|
||
async def state_callback( | ||
self, entity: Optional[str], attribute: Optional[str], old, new, kwargs | ||
) -> None: | ||
await self.controller.handle_action(new) |
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,24 @@ | ||
class A: | ||
def log(self, message): | ||
print(message) | ||
|
||
|
||
class B(A): | ||
def foo(self): | ||
return "foo from B" | ||
|
||
|
||
class C(A): | ||
def foo(self): | ||
return "foo from C" | ||
|
||
|
||
class D(B, C): | ||
def bar(self): | ||
print(B.foo(self)) | ||
print(C.foo(self)) | ||
self.log("testtt") | ||
|
||
|
||
d = D() | ||
print(d.foo()) |
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