-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Add discovery notify support and mysensors notify #4014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
MartinHjelmare
wants to merge
5
commits into
home-assistant:dev
from
MartinHjelmare:add-mysensors-notify
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,63 @@ | ||
""" | ||
MySensors notification service. | ||
|
||
For more details about this platform, please refer to the documentation | ||
https://home-assistant.io/components/notify.mysensors/ | ||
""" | ||
from homeassistant.components import mysensors | ||
from homeassistant.components.notify import (ATTR_TARGET, | ||
BaseNotificationService) | ||
|
||
|
||
def get_service(hass, config): | ||
"""Get the MySensors notification service.""" | ||
platform_devices = [] | ||
gateways = hass.data.get(mysensors.MYSENSORS_GATEWAYS) | ||
if not gateways: | ||
return | ||
|
||
for gateway in gateways: | ||
pres = gateway.const.Presentation | ||
set_req = gateway.const.SetReq | ||
map_sv_types = { | ||
pres.S_INFO: [set_req.V_TEXT], | ||
} | ||
devices = {} | ||
gateway.platform_callbacks.append(mysensors.pf_callback_factory( | ||
map_sv_types, devices, MySensorsNotificationDevice)) | ||
platform_devices.append(devices) | ||
|
||
return MySensorsNotificationService(platform_devices) | ||
|
||
|
||
class MySensorsNotificationDevice(mysensors.MySensorsDeviceEntity): | ||
"""Represent a MySensors Notification device.""" | ||
|
||
def send_msg(self, msg): | ||
"""Send a message.""" | ||
for sub_msg in [msg[i:i + 25] for i in range(0, len(msg), 25)]: | ||
# Max mysensors payload is 25 bytes. | ||
self.gateway.set_child_value( | ||
self.node_id, self.child_id, self.value_type, sub_msg) | ||
|
||
|
||
class MySensorsNotificationService(BaseNotificationService): | ||
"""Implement MySensors notification service.""" | ||
|
||
# pylint: disable=too-few-public-methods | ||
|
||
def __init__(self, platform_devices): | ||
"""Initialize the service.""" | ||
self.platform_devices = platform_devices | ||
|
||
def send_message(self, message="", **kwargs): | ||
"""Send a message to a user.""" | ||
target_devices = kwargs.get(ATTR_TARGET) | ||
devices = [ | ||
device for gw_devs in self.platform_devices | ||
for device in gw_devs.values() | ||
if target_devices is None or | ||
device.name in target_devices] | ||
|
||
for device in devices: | ||
device.send_msg(message) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
from homeassistant.bootstrap import setup_component | ||
import homeassistant.components.notify as notify | ||
from tests.common import get_test_home_assistant | ||
from tests.common import assert_setup_component, get_test_home_assistant | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'assert_setup_component' imported but unused |
||
|
||
|
||
class TestCommandLine(unittest.TestCase): | ||
|
@@ -29,15 +29,6 @@ def test_setup(self): | |
'command': 'echo $(cat); exit 1', | ||
}}) | ||
|
||
def test_bad_config(self): | ||
"""Test set up the platform with bad/missing configuration.""" | ||
self.assertFalse(setup_component(self.hass, notify.DOMAIN, { | ||
'notify': { | ||
'name': 'test', | ||
'platform': 'bad_platform', | ||
} | ||
})) | ||
|
||
def test_command_line_output(self): | ||
"""Test the command line output.""" | ||
with tempfile.TemporaryDirectory() as tempdirname: | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a good idea, using the passed discovery info directly as config for the platform?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.