{"action":"created","comment":{"url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/comments/133305280","pull_request_review_id":56471944,"id":133305280,"diff_hunk":"@@ -0,0 +1,173 @@\n+\"\"\"\n+Use Bayesian Inference to trigger a binary sensor.\n+\n+For more details about this platform, please refer to the documentation at\n+https://home-assistant.io/components/sensor.bayesian_binary/\n+\"\"\"\n+import asyncio\n+import logging\n+from collections import OrderedDict\n+\n+import voluptuous as vol\n+\n+import homeassistant.helpers.config_validation as cv\n+from homeassistant.components.binary_sensor import (BinarySensorDevice,\n+                                                    PLATFORM_SCHEMA)\n+from homeassistant.const import (CONF_NAME, STATE_UNKNOWN, CONF_DEVICE_CLASS)\n+from homeassistant.core import callback\n+from homeassistant.helpers import condition\n+from homeassistant.helpers.event import async_track_state_change\n+\n+_LOGGER = logging.getLogger(__name__)\n+\n+CONF_PROBABILITY_THRESHOLD = 'probability_threshold'\n+CONF_OBSERVATIONS = 'observations'\n+CONF_PRIOR = 'prior'\n+\n+DEFAULT_NAME = 'BayesianBinary'\n+\n+PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({\n+    vol.Optional(CONF_NAME, default=DEFAULT_NAME):\n+    cv.string,\n+    vol.Required(CONF_OBSERVATIONS):\n+    vol.Schema([dict]),\n+    vol.Required(CONF_PRIOR):\n+    vol.Coerce(float),\n+    vol.Required(CONF_PROBABILITY_THRESHOLD):\n+    vol.Coerce(float),\n+})\n+\n+\n+@asyncio.coroutine\n+def async_setup_platform(hass, config, async_add_devices, discovery_info=None):\n+    \"\"\"Set up the Threshold sensor.\"\"\"\n+    name = config.get(CONF_NAME)\n+    observations = config.get(CONF_OBSERVATIONS)\n+    prior = config.get(CONF_PRIOR)\n+    probability_threshold = config.get(CONF_PROBABILITY_THRESHOLD)\n+    device_class = config.get(CONF_DEVICE_CLASS)","path":"homeassistant/components/binary_sensor/bayesian.py","position":48,"original_position":48,"commit_id":"39465c18ed36d277157d45c2ac50b346a51a701a","original_commit_id":"39465c18ed36d277157d45c2ac50b346a51a701a","user":{"login":"MartinHjelmare","id":3181692,"avatar_url":"https://avatars0.githubusercontent.com/u/3181692?v=4","gravatar_id":"","url":"https://api.github.com/users/MartinHjelmare","html_url":"https://github.com/MartinHjelmare","followers_url":"https://api.github.com/users/MartinHjelmare/followers","following_url":"https://api.github.com/users/MartinHjelmare/following{/other_user}","gists_url":"https://api.github.com/users/MartinHjelmare/gists{/gist_id}","starred_url":"https://api.github.com/users/MartinHjelmare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MartinHjelmare/subscriptions","organizations_url":"https://api.github.com/users/MartinHjelmare/orgs","repos_url":"https://api.github.com/users/MartinHjelmare/repos","events_url":"https://api.github.com/users/MartinHjelmare/events{/privacy}","received_events_url":"https://api.github.com/users/MartinHjelmare/received_events","type":"User","site_admin":false},"body":"`CONF_DEVICE_CLASS` isn't part of the config schema.","created_at":"2017-08-15T21:13:16Z","updated_at":"2017-08-15T21:13:16Z","html_url":"https://github.com/home-assistant/home-assistant/pull/8810#discussion_r133305280","pull_request_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/8810","_links":{"self":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/comments/133305280"},"html":{"href":"https://github.com/home-assistant/home-assistant/pull/8810#discussion_r133305280"},"pull_request":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/8810"}}},"pull_request":{"url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/8810","id":134066241,"html_url":"https://github.com/home-assistant/home-assistant/pull/8810","diff_url":"https://github.com/home-assistant/home-assistant/pull/8810.diff","patch_url":"https://github.com/home-assistant/home-assistant/pull/8810.patch","issue_url":"https://api.github.com/repos/home-assistant/home-assistant/issues/8810","number":8810,"state":"open","locked":false,"title":"Bayesian Binary Sensor","user":{"login":"jlmcgehee21","id":8727616,"avatar_url":"https://avatars3.githubusercontent.com/u/8727616?v=4","gravatar_id":"","url":"https://api.github.com/users/jlmcgehee21","html_url":"https://github.com/jlmcgehee21","followers_url":"https://api.github.com/users/jlmcgehee21/followers","following_url":"https://api.github.com/users/jlmcgehee21/following{/other_user}","gists_url":"https://api.github.com/users/jlmcgehee21/gists{/gist_id}","starred_url":"https://api.github.com/users/jlmcgehee21/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlmcgehee21/subscriptions","organizations_url":"https://api.github.com/users/jlmcgehee21/orgs","repos_url":"https://api.github.com/users/jlmcgehee21/repos","events_url":"https://api.github.com/users/jlmcgehee21/events{/privacy}","received_events_url":"https://api.github.com/users/jlmcgehee21/received_events","type":"User","site_admin":false},"body":"## Description:\r\nWhy:\r\n\r\n* It would be beneficial to leverage various sensor outputs in a\r\nBayesian manner in order to sense more complex events.\r\n\r\nThis change addresses the need by:\r\n\r\n* `BayesianBinarySensor` class in\r\n`./homeassistant/components/binary_sensor/bayesian.py`\r\n* Tests in `./tests/components/binary_sensor/test_bayesian.py`\r\n\r\nCaveats:\r\nThis is my first time in this code-base. I did try to follow conventions\r\nthat I was able to find, but I'm sure there will be some issues to\r\nstraighten out.\r\n\r\n## Example entry for `configuration.yaml` (if applicable):\r\n```\r\nbinary_sensor:\r\n  name: 'currently_cooking'\r\n  platform: 'bayesian'\r\n  prior: 0.1\r\n  probability_threshold: 0.7\r\n  observations:\r\n    - entity_id: 'switch.kitchen_lights'\r\n      probability: 0.6\r\n      platform: 'state'\r\n      to_state: 'on'\r\n    - entity_id: 'sensor.stove_temperature'\r\n      probability: 0.9\r\n      platform: 'numeric_state'\r\n      above: 100\r\n    - entity_id: 'sensor.kitchen_motion'\r\n      probability: 0.5\r\n      platform: 'state'\r\n      to_state: 'on'\r\n\r\nbinary_sensor:\r\n  name: 'in_bed'\r\n  platform: 'bayesian'\r\n  prior: 0.5\r\n  probability_threshold: 0.95\r\n  observations:\r\n    - entity_id: 'sensor.living_room_motion'\r\n      probability: 0.4\r\n      platform: 'state'\r\n      to_state: 'off'\r\n    - entity_id: 'sensor.basement_motion'\r\n      probability: 0.2\r\n      platform: 'state'\r\n      to_state: 'off'\r\n    - entity_id: 'sensor.bedroom_motion'\r\n      probability: 0.5\r\n      platform: 'state'\r\n      to_state: 'on'\r\n    - entity_id: 'sensor.sun'\r\n      probability: 0.7\r\n      platform: 'state'\r\n      to_state: 'below_horizon'\r\n```\r\n\r\n## Checklist:\r\n\r\nIf user exposed functionality or configuration variables are added/changed:\r\n  - [ ] Documentation added/updated in [home-assistant.github.io](https://github.com/home-assistant/home-assistant.github.io)\r\n\r\n\r\nIf the code does not interact with devices:\r\n  - [x] Local tests with `tox` run successfully. **Your PR cannot be merged unless tests pass**\r\n  - [x] Tests have been added to verify that the new code works.\r\n\r\n[ex-requir]: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/keyboard.py#L14\r\n[ex-import]: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/keyboard.py#L54\r\n","created_at":"2017-08-03T23:59:14Z","updated_at":"2017-08-15T21:13:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0f10420d26bc8fed5021f0cdd6953a18d8d23cf9","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/8810/commits","review_comments_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/8810/comments","review_comment_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/comments{/number}","comments_url":"https://api.github.com/repos/home-assistant/home-assistant/issues/8810/comments","statuses_url":"https://api.github.com/repos/home-assistant/home-assistant/statuses/39465c18ed36d277157d45c2ac50b346a51a701a","head":{"label":"jlmcgehee21:feature/bayesian_binary","ref":"feature/bayesian_binary","sha":"39465c18ed36d277157d45c2ac50b346a51a701a","user":{"login":"jlmcgehee21","id":8727616,"avatar_url":"https://avatars3.githubusercontent.com/u/8727616?v=4","gravatar_id":"","url":"https://api.github.com/users/jlmcgehee21","html_url":"https://github.com/jlmcgehee21","followers_url":"https://api.github.com/users/jlmcgehee21/followers","following_url":"https://api.github.com/users/jlmcgehee21/following{/other_user}","gists_url":"https://api.github.com/users/jlmcgehee21/gists{/gist_id}","starred_url":"https://api.github.com/users/jlmcgehee21/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlmcgehee21/subscriptions","organizations_url":"https://api.github.com/users/jlmcgehee21/orgs","repos_url":"https://api.github.com/users/jlmcgehee21/repos","events_url":"https://api.github.com/users/jlmcgehee21/events{/privacy}","received_events_url":"https://api.github.com/users/jlmcgehee21/received_events","type":"User","site_admin":false},"repo":{"id":77547081,"name":"home-assistant","full_name":"jlmcgehee21/home-assistant","owner":{"login":"jlmcgehee21","id":8727616,"avatar_url":"https://avatars3.githubusercontent.com/u/8727616?v=4","gravatar_id":"","url":"https://api.github.com/users/jlmcgehee21","html_url":"https://github.com/jlmcgehee21","followers_url":"https://api.github.com/users/jlmcgehee21/followers","following_url":"https://api.github.com/users/jlmcgehee21/following{/other_user}","gists_url":"https://api.github.com/users/jlmcgehee21/gists{/gist_id}","starred_url":"https://api.github.com/users/jlmcgehee21/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlmcgehee21/subscriptions","organizations_url":"https://api.github.com/users/jlmcgehee21/orgs","repos_url":"https://api.github.com/users/jlmcgehee21/repos","events_url":"https://api.github.com/users/jlmcgehee21/events{/privacy}","received_events_url":"https://api.github.com/users/jlmcgehee21/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jlmcgehee21/home-assistant","description":":house_with_garden: Open-source home automation platform running on Python 3","fork":true,"url":"https://api.github.com/repos/jlmcgehee21/home-assistant","forks_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/forks","keys_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/teams","hooks_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/hooks","issue_events_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/issues/events{/number}","events_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/events","assignees_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/assignees{/user}","branches_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/branches{/branch}","tags_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/tags","blobs_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/git/refs{/sha}","trees_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/statuses/{sha}","languages_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/languages","stargazers_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/stargazers","contributors_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/contributors","subscribers_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/subscribers","subscription_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/subscription","commits_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/commits{/sha}","git_commits_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/git/commits{/sha}","comments_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/comments{/number}","issue_comment_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/issues/comments{/number}","contents_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/contents/{+path}","compare_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/merges","archive_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/downloads","issues_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/issues{/number}","pulls_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/pulls{/number}","milestones_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/milestones{/number}","notifications_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/labels{/name}","releases_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/releases{/id}","deployments_url":"https://api.github.com/repos/jlmcgehee21/home-assistant/deployments","created_at":"2016-12-28T16:40:51Z","updated_at":"2016-12-28T16:40:57Z","pushed_at":"2017-08-06T17:05:34Z","git_url":"git://github.com/jlmcgehee21/home-assistant.git","ssh_url":"git@github.com:jlmcgehee21/home-assistant.git","clone_url":"https://github.com/jlmcgehee21/home-assistant.git","svn_url":"https://github.com/jlmcgehee21/home-assistant","homepage":"https://home-assistant.io","size":67422,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"dev"}},"base":{"label":"home-assistant:dev","ref":"dev","sha":"c895f1f1db26697fcd096f57cf3ce39662b739a7","user":{"login":"home-assistant","id":13844975,"avatar_url":"https://avatars3.githubusercontent.com/u/13844975?v=4","gravatar_id":"","url":"https://api.github.com/users/home-assistant","html_url":"https://github.com/home-assistant","followers_url":"https://api.github.com/users/home-assistant/followers","following_url":"https://api.github.com/users/home-assistant/following{/other_user}","gists_url":"https://api.github.com/users/home-assistant/gists{/gist_id}","starred_url":"https://api.github.com/users/home-assistant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/home-assistant/subscriptions","organizations_url":"https://api.github.com/users/home-assistant/orgs","repos_url":"https://api.github.com/users/home-assistant/repos","events_url":"https://api.github.com/users/home-assistant/events{/privacy}","received_events_url":"https://api.github.com/users/home-assistant/received_events","type":"Organization","site_admin":false},"repo":{"id":12888993,"name":"home-assistant","full_name":"home-assistant/home-assistant","owner":{"login":"home-assistant","id":13844975,"avatar_url":"https://avatars3.githubusercontent.com/u/13844975?v=4","gravatar_id":"","url":"https://api.github.com/users/home-assistant","html_url":"https://github.com/home-assistant","followers_url":"https://api.github.com/users/home-assistant/followers","following_url":"https://api.github.com/users/home-assistant/following{/other_user}","gists_url":"https://api.github.com/users/home-assistant/gists{/gist_id}","starred_url":"https://api.github.com/users/home-assistant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/home-assistant/subscriptions","organizations_url":"https://api.github.com/users/home-assistant/orgs","repos_url":"https://api.github.com/users/home-assistant/repos","events_url":"https://api.github.com/users/home-assistant/events{/privacy}","received_events_url":"https://api.github.com/users/home-assistant/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/home-assistant/home-assistant","description":":house_with_garden: Open-source home automation platform running on Python 3","fork":false,"url":"https://api.github.com/repos/home-assistant/home-assistant","forks_url":"https://api.github.com/repos/home-assistant/home-assistant/forks","keys_url":"https://api.github.com/repos/home-assistant/home-assistant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/home-assistant/home-assistant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/home-assistant/home-assistant/teams","hooks_url":"https://api.github.com/repos/home-assistant/home-assistant/hooks","issue_events_url":"https://api.github.com/repos/home-assistant/home-assistant/issues/events{/number}","events_url":"https://api.github.com/repos/home-assistant/home-assistant/events","assignees_url":"https://api.github.com/repos/home-assistant/home-assistant/assignees{/user}","branches_url":"https://api.github.com/repos/home-assistant/home-assistant/branches{/branch}","tags_url":"https://api.github.com/repos/home-assistant/home-assistant/tags","blobs_url":"https://api.github.com/repos/home-assistant/home-assistant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/home-assistant/home-assistant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/home-assistant/home-assistant/git/refs{/sha}","trees_url":"https://api.github.com/repos/home-assistant/home-assistant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/home-assistant/home-assistant/statuses/{sha}","languages_url":"https://api.github.com/repos/home-assistant/home-assistant/languages","stargazers_url":"https://api.github.com/repos/home-assistant/home-assistant/stargazers","contributors_url":"https://api.github.com/repos/home-assistant/home-assistant/contributors","subscribers_url":"https://api.github.com/repos/home-assistant/home-assistant/subscribers","subscription_url":"https://api.github.com/repos/home-assistant/home-assistant/subscription","commits_url":"https://api.github.com/repos/home-assistant/home-assistant/commits{/sha}","git_commits_url":"https://api.github.com/repos/home-assistant/home-assistant/git/commits{/sha}","comments_url":"https://api.github.com/repos/home-assistant/home-assistant/comments{/number}","issue_comment_url":"https://api.github.com/repos/home-assistant/home-assistant/issues/comments{/number}","contents_url":"https://api.github.com/repos/home-assistant/home-assistant/contents/{+path}","compare_url":"https://api.github.com/repos/home-assistant/home-assistant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/home-assistant/home-assistant/merges","archive_url":"https://api.github.com/repos/home-assistant/home-assistant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/home-assistant/home-assistant/downloads","issues_url":"https://api.github.com/repos/home-assistant/home-assistant/issues{/number}","pulls_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls{/number}","milestones_url":"https://api.github.com/repos/home-assistant/home-assistant/milestones{/number}","notifications_url":"https://api.github.com/repos/home-assistant/home-assistant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/home-assistant/home-assistant/labels{/name}","releases_url":"https://api.github.com/repos/home-assistant/home-assistant/releases{/id}","deployments_url":"https://api.github.com/repos/home-assistant/home-assistant/deployments","created_at":"2013-09-17T07:29:48Z","updated_at":"2017-08-15T18:44:42Z","pushed_at":"2017-08-15T18:33:05Z","git_url":"git://github.com/home-assistant/home-assistant.git","ssh_url":"git@github.com:home-assistant/home-assistant.git","clone_url":"https://github.com/home-assistant/home-assistant.git","svn_url":"https://github.com/home-assistant/home-assistant","homepage":"https://home-assistant.io","size":69772,"stargazers_count":7814,"watchers_count":7814,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2381,"mirror_url":null,"open_issues_count":450,"forks":2381,"open_issues":450,"watchers":7814,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/8810"},"html":{"href":"https://github.com/home-assistant/home-assistant/pull/8810"},"issue":{"href":"https://api.github.com/repos/home-assistant/home-assistant/issues/8810"},"comments":{"href":"https://api.github.com/repos/home-assistant/home-assistant/issues/8810/comments"},"review_comments":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/8810/comments"},"review_comment":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/8810/commits"},"statuses":{"href":"https://api.github.com/repos/home-assistant/home-assistant/statuses/39465c18ed36d277157d45c2ac50b346a51a701a"}}}}
{"actor":{"display_login":"MartinHjelmare"}}