Compare commits
664 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d0bcec12b9 | |||
| 9fc62c1851 | |||
| 23d88cd4ad | |||
| 86f433067c | |||
| 75232c43ce | |||
| 01a743c7d4 | |||
| 28f4283b40 | |||
| 375faa9c91 | |||
| ef132e4583 | |||
| 05cbe54db3 | |||
| ae7697b900 | |||
| a8f7bc2324 | |||
| 9db0987e53 | |||
| 515307b404 | |||
| 03e7ac2a0e | |||
| c5cdf6d7cf | |||
| a3abd8bb08 | |||
| 5a7e380396 | |||
| 09ef2e1b8c | |||
| 80d2f35cc5 | |||
| ad57f27989 | |||
| a6720f54b3 | |||
| aaf75c7e45 | |||
| c5de42e7b5 | |||
| d6bb6a0777 | |||
| f87c7d6732 | |||
| 575e97a051 | |||
| 902077d78b | |||
| c17a4fca80 | |||
| 241a768983 | |||
| 72cca0a91a | |||
| dd7a7f4c75 | |||
| 468a8a1013 | |||
| 24d84dbb42 | |||
| 893a14e8db | |||
| cbc6323438 | |||
| d6db00b55a | |||
| eebb736bf8 | |||
| f192a15a8f | |||
| 9ec44fbe32 | |||
| ffc06e8bcb | |||
| 9c7b2ce9fd | |||
| 1de7dcdb5f | |||
| 9e7886b909 | |||
| 4045fb6862 | |||
| dda4f84150 | |||
| fda88f8fda | |||
| 3c05c8d1db | |||
| 21ec435430 | |||
| 24893bc28d | |||
| 403b9cbe3e | |||
| 8b0d19835c | |||
| c31522eea9 | |||
| ee33aa73e1 | |||
| 47498e4aa9 | |||
| ef4661f1e6 | |||
| b4070cfb78 | |||
| c750f16275 | |||
| 2248c271fa | |||
| 87b33d5098 | |||
| cf7c06d307 | |||
| 70d95cb6aa | |||
| 2c151c6db9 | |||
| 3fc5a60634 | |||
| 94d2f23cfc | |||
| 4bd102ddf5 | |||
| 232aa792f1 | |||
| ce9f76a0be | |||
| f3f592cdec | |||
| 1d2cd0811b | |||
| 886b581d2a | |||
| 88387d3123 | |||
| 14cd27aaa7 | |||
| 2e175b88bc | |||
| 537a7789fd | |||
| 80d1ab78dd | |||
| 821238f889 | |||
| 33a9ec0106 | |||
| a8f0f313c8 | |||
| 6796219f37 | |||
| 1dae22a465 | |||
| 7aba78f96e | |||
| 06cf07b097 | |||
| 271af2c608 | |||
| 8c6ce217e6 | |||
| 5410a0c8f6 | |||
| 1a422ecd5a | |||
| 6add5e387b | |||
| ca070a36e3 | |||
| 2c3a6e7905 | |||
| 0a4e857901 | |||
| d4b444823c | |||
| 2382dffbf4 | |||
| 33b0f4d05d | |||
| 5b6371ecda | |||
| 6f1f8ffea0 | |||
| 1f6f2de9c6 | |||
| b13e48bd71 | |||
| 9a79ecf2d3 | |||
| ebd475b380 | |||
| cff77a175d | |||
| 726637b867 | |||
| 9117fa6eb8 | |||
| 6ae57b5aaf | |||
| e8e2814313 | |||
| a918be517d | |||
| ec5d88b98e | |||
| 13fbefcdf8 | |||
| f4c9540a1b | |||
| e72f61ce73 | |||
| 4c056db3bb | |||
| c10a86d1bf | |||
| b97de5cef6 | |||
| 4233c0bc66 | |||
| b13008201e | |||
| 125ad8630d | |||
| 5c3ad5d4c0 | |||
| 414aa8563d | |||
| d08a181c72 | |||
| 80c6bf6744 | |||
| b1ba792715 | |||
| b99f6c1a46 | |||
| 1397f9e588 | |||
| bb7f92330d | |||
| 7cbd780748 | |||
| 784fea2d56 | |||
| 97f0425252 | |||
| 11120a8743 | |||
| 8009542b3e | |||
| 32cfa6998c | |||
| d10a5cf5e9 | |||
| 4089a7a0d3 | |||
| 5a926913d3 | |||
| 6c91831baa | |||
| 069dafa3a5 | |||
| 4abc5c97cd | |||
| bb3dd47088 | |||
| f6c53896e3 | |||
| ad2e2d916b | |||
| 8406f81811 | |||
| bcdfc555e0 | |||
| 3b89102338 | |||
| 60dd2d441d | |||
| 5830da63b1 | |||
| 50561ffe97 | |||
| 74e8446556 | |||
| d94db5388c | |||
| f66aeb2e73 | |||
| 54b82ecd91 | |||
| 2fa98167c2 | |||
| 57725136c0 | |||
| 40dbeb0b60 | |||
| ef92940ffb | |||
| e7865c1d67 | |||
| 02e634c6a2 | |||
| 0f937cad74 | |||
| 81dd1515ae | |||
| a65d0f0549 | |||
| 881c82c2df | |||
| df94c909f7 | |||
| a0ed469aa2 | |||
| afa4fc4ef5 | |||
| df450c3d1f | |||
| dc5d652d31 | |||
| e4fe19fff0 | |||
| f6f3f54228 | |||
| 6df67d2852 | |||
| 2411d1f2c8 | |||
| 9f6a1c75fa | |||
| 1842e5909e | |||
| 6f31aacb90 | |||
| e541b9ba77 | |||
| 53484e46a3 | |||
| de79a46d43 | |||
| bc19ef66bf | |||
| de08f0afaa | |||
| 706bbeae16 | |||
| e5497d89f4 | |||
| 048ec0aa66 | |||
| 03ed85b0a7 | |||
| 9d92707fd7 | |||
| 90c392e270 | |||
| 6cb6cbfefd | |||
| 6d2bca0fd1 | |||
| 99286391e1 | |||
| 711f2da496 | |||
| fbd68b6f89 | |||
| 85ebd0ab59 | |||
| 58034219b6 | |||
| 17f5a466d9 | |||
| 90ca6a0998 | |||
| ec2b433733 | |||
| 492c4b7f00 | |||
| b3beb9f3c9 | |||
| 837e7affa7 | |||
| 6d527842dd | |||
| e30915eb2c | |||
| 43e2b58f20 | |||
| d3c6c892a8 | |||
| a63edcf505 | |||
| 0e7088ce3b | |||
| 0042e7725d | |||
| 613f8d0bd2 | |||
| 61ca1ab2c1 | |||
| ad62591f43 | |||
| 5ba33bc40e | |||
| 143b08d661 | |||
| 87a9fd8252 | |||
| b1f7b5c6d7 | |||
| bb97af1504 | |||
| 9a092654e9 | |||
| d59b98ee2b | |||
| 6bbbbd9e17 | |||
| 9fbedd8b5f | |||
| a91163877f | |||
| 0acce86596 | |||
| c95b03f240 | |||
| 56ce3e5f5a | |||
| 8b5751ad44 | |||
| c615272c06 | |||
| a3b8122707 | |||
| 682e3460e0 | |||
| 71dbd10b39 | |||
| 7f143bcdf9 | |||
| f19a46dcfe | |||
| 625f69443a | |||
| 0bdd293572 | |||
| f8072aae68 | |||
| 92afcae9be | |||
| a6f37c032b | |||
| e66d15b71d | |||
| 1098194a89 | |||
| 66d23cd15f | |||
| c3a1193ef9 | |||
| ec2d9af8dc | |||
| f0e44728d7 | |||
| f67747456f | |||
| f6017a17b2 | |||
| 89aa3cbc62 | |||
| 543190dfb0 | |||
| fdc8c45a69 | |||
| d2d421ca8f | |||
| 7ad5b3a17b | |||
| c8dd9696b4 | |||
| 58ef69b95d | |||
| 0de9229d75 | |||
| f4c3ac2a62 | |||
| 6c5ceaf686 | |||
| 54f65ae87d | |||
| 4f2dc3cc2a | |||
| a4ee2bd8ef | |||
| d4629a7efe | |||
| 441ae73344 | |||
| 9249dc6dd3 | |||
| 4c4539caff | |||
| 4c0ff0e0d0 | |||
| 1ceee2d6c5 | |||
| cbb74d50ce | |||
| c2d72bbf09 | |||
| f97ba263c4 | |||
| 85df9e98bd | |||
| 2faafb9c0f | |||
| d43101f22a | |||
| 3d23cd10fc | |||
| 66cd8d264e | |||
| 291910d74e | |||
| 7ac648d0ab | |||
| 3b42390062 | |||
| a80917f530 | |||
| 8fbb585874 | |||
| 027d97321f | |||
| 62a1c9687e | |||
| a9c6f8c1d9 | |||
| 06b4fcc2cf | |||
| 6dc2501116 | |||
| 54060f27ef | |||
| 85aa4fdd2e | |||
| 0624445627 | |||
| 4ca4941c82 | |||
| 4dbd84ead0 | |||
| 0495776a22 | |||
| dd35551047 | |||
| 9f61369156 | |||
| bd536be66d | |||
| c5b69a0ee4 | |||
| 206b3a88a2 | |||
| 880bd011a9 | |||
| 7de91a270a | |||
| 09973abe8a | |||
| 342a819fd4 | |||
| 4bf185c868 | |||
| 78742c016b | |||
| 1ed314f6f6 | |||
| be23c6c86d | |||
| a194c4f1bd | |||
| edb24add6b | |||
| bc88985889 | |||
| 3d27dd3ec4 | |||
| c2f5eb3073 | |||
| 541b268721 | |||
| e77daed086 | |||
| fdbb409331 | |||
| f96c5aa62f | |||
| c07a096e57 | |||
| 48b6c5b5cb | |||
| d8d59d9a66 | |||
| 702dddbb2f | |||
| 127488004c | |||
| 7c925ac295 | |||
| 8617b92d1b | |||
| bb80e3a9fc | |||
| 80023f62d9 | |||
| 9617288bd5 | |||
| 4fd79afa42 | |||
| 719f9a63d9 | |||
| 4bc33d0352 | |||
| c4e1035638 | |||
| d40e889d3b | |||
| 41acc8fa43 | |||
| 90c2aed7b4 | |||
| 5108602de3 | |||
| 5ee17ffc58 | |||
| 6b899ddc1d | |||
| 0a711922ef | |||
| 475b631d9c | |||
| 40c75f0a51 | |||
| 1dd99a6d5d | |||
| bed9b038c8 | |||
| 9210c57c2d | |||
| 313cbda0aa | |||
| 86b0e49995 | |||
| a39148dd38 | |||
| b8c8c71b78 | |||
| 65a3bf2325 | |||
| ac34db3c8a | |||
| f2e86ecd8e | |||
| 7b993da0de | |||
| de5bee6359 | |||
| 34f124190c | |||
| d867366be1 | |||
| d0d375d433 | |||
| d17aa103b4 | |||
| f0af23a4f5 | |||
| bdd6bb7918 | |||
| 3ec49a0ef0 | |||
| 7a2d049ce3 | |||
| 7fba4b354e | |||
| 87cecd7e95 | |||
| 303cb8e350 | |||
| 236ae94474 | |||
| 308969e6dd | |||
| 4dd558a420 | |||
| 0e6a60b086 | |||
| 4fc0163139 | |||
| 314d34a644 | |||
| 2745b0f99e | |||
| c2e8646aed | |||
| e5919c1bfe | |||
| c8961fcf99 | |||
| 58cee75c0e | |||
| 4f13236008 | |||
| 2a377a6125 | |||
| 058dba50cc | |||
| e6846e7eb9 | |||
| a0ddda4bc6 | |||
| 57c0f96118 | |||
| a84429538b | |||
| 07953fb7e3 | |||
| 12da6f531e | |||
| 769f5aafb7 | |||
| a1abab8ced | |||
| 270a998e3c | |||
| d829497c3d | |||
| a8d5b0e5ec | |||
| 85d732a45a | |||
| 8f3e8d29f0 | |||
| ee4543d739 | |||
| 59456f20fb | |||
| 4a1f609893 | |||
| 36214c73ee | |||
| 20a1025a8c | |||
| ec85884d92 | |||
| 22c01b956f | |||
| 9cdf84dacf | |||
| 60f40800c4 | |||
| 3b7b12bbd5 | |||
| 9a1aad8e92 | |||
| 6f398f59df | |||
| 8ace656657 | |||
| a4481efe07 | |||
| dc31ddbef2 | |||
| 0c2fe4c5f3 | |||
| 03febb81d3 | |||
| 6f1a25d8d6 | |||
| f182f7dccd | |||
| 31fcd230b1 | |||
| 1ad5cae98e | |||
| 5af4864326 | |||
| ea8d278f8f | |||
| 88de9908ce | |||
| 1bbecce5eb | |||
| 2495226c87 | |||
| c1aa1fb0e0 | |||
| a5b198e2b8 | |||
| cd669239ae | |||
| bc73a6829d | |||
| 542b640ef0 | |||
| 7823fb9788 | |||
| bcb42674fc | |||
| 1f1a46a8bd | |||
| 7b999e6cd1 | |||
| c97a25cc86 | |||
| cdf24ec205 | |||
| 579f4d4cca | |||
| fce04e7ad0 | |||
| 6c94650603 | |||
| fca8ad5b0b | |||
| 4b4fb038e3 | |||
| 0b3a66dd1a | |||
| 2d8cf7de44 | |||
| ad931eac60 | |||
| 438e78610d | |||
| 058f6f9303 | |||
| 73cdf00512 | |||
| 12b5caed70 | |||
| 18d2668e3b | |||
| af21f72d17 | |||
| b64680e4a8 | |||
| 9faedf0e67 | |||
| 204c151113 | |||
| 9b8256ec07 | |||
| d61eb93c03 | |||
| a2c6cde83d | |||
| 825c91f0c3 | |||
| d406d7fa94 | |||
| 3db6faab4d | |||
| 15a046f20c | |||
| d3cd304f68 | |||
| 84fb96a42f | |||
| 5a1fed3980 | |||
| bb8af3a2d5 | |||
| 2803631906 | |||
| 4c47ed31ff | |||
| 1ed574b2a0 | |||
| d69c1b848a | |||
| 35c29dac3f | |||
| aac44f3a2b | |||
| 17dd8ddc9a | |||
| a8b36d9baa | |||
| 520a8d0d0d | |||
| 033bd30391 | |||
| 99e14380fe | |||
| 5576649d60 | |||
| 82cd2f4ed6 | |||
| 66f12afbb1 | |||
| 431656bbcf | |||
| a174a06e5c | |||
| 0d0fdb0adf | |||
| 5f8dd65acf | |||
| 601211f1d9 | |||
| 8983a97c70 | |||
| 2e899bd61c | |||
| d0a8a57ae4 | |||
| 08aabd18ad | |||
| 2478623ebc | |||
| 736183e6f5 | |||
| 31f2707b2f | |||
| d244d3b599 | |||
| 82904c59ce | |||
| f8b2570cb3 | |||
| 6268840b55 | |||
| c9ff0ab7eb | |||
| cf1f9a29bf | |||
| 48b1f8e137 | |||
| 4b96a7c820 | |||
| 452ebdac8e | |||
| 7dc1499386 | |||
| 3ccc7787af | |||
| 02879e79e6 | |||
| 305c87a9c9 | |||
| 3abc78eef2 | |||
| 4a421e25b0 | |||
| 86047eceb1 | |||
| 7edbb6aadc | |||
| 0361f37178 | |||
| 55c5d254d5 | |||
| 36f5caa214 | |||
| 8c7898ed05 | |||
| 39de92960d | |||
| 6d35bdafee | |||
| 217ffc215b | |||
| cbd3860585 | |||
| 5804dde0e9 | |||
| e9b2cf1600 | |||
| cdf2179b3e | |||
| 8f2ca856c7 | |||
| 622a6deb04 | |||
| a698bc477d | |||
| a36ae4b24a | |||
| c703c89dbd | |||
| b3227e491b | |||
| 9e83a80215 | |||
| 9c85702c87 | |||
| 9b7b39055d | |||
| 11f32d0500 | |||
| 326e26fbeb | |||
| 394c87c40b | |||
| ce152e9c94 | |||
| 9e0946b207 | |||
| da77edf8fc | |||
| 6cb991d583 | |||
| f8e5df237b | |||
| 5d953061e8 | |||
| 1bcca8cba1 | |||
| bdb6182921 | |||
| 55d1ad94ef | |||
| 6773c35760 | |||
| 5f89b34831 | |||
| 90ae5c6646 | |||
| a8bb75d070 | |||
| d82859b6ea | |||
| 7d41ce4e46 | |||
| c23375a18b | |||
| 4c4e5d5f47 | |||
| 6ff24ed047 | |||
| 69ed6fe6e7 | |||
| 4e2d75a8f4 | |||
| ae0dbbcfa5 | |||
| 25e1432403 | |||
| adfcfad488 | |||
| b0734e613f | |||
| 913c5ab47c | |||
| 429904c437 | |||
| 41a36df801 | |||
| 56a2ffca1d | |||
| 6e2fb17f19 | |||
| 586be7fad1 | |||
| d9b30d1421 | |||
| e9059a3ed9 | |||
| 473d6b1d05 | |||
| 7f17a50b4a | |||
| c7183a14a5 | |||
| c1eaf60461 | |||
| ca6b957839 | |||
| 680385df93 | |||
| 62f21c3ac6 | |||
| acfbbb3898 | |||
| 4403fe941d | |||
| 244fde880e | |||
| df99e4ef22 | |||
| 976d9f2d08 | |||
| f5dd146676 | |||
| 7b00b19223 | |||
| b114ba56ea | |||
| 0d32bd7a19 | |||
| 4feef3dd0d | |||
| 9c3b1b7a96 | |||
| a09d731058 | |||
| 27e35d5f34 | |||
| c8fa6cc127 | |||
| 468087e6bc | |||
| d4b6a7343f | |||
| 87c88078c8 | |||
| 8c1ebde1de | |||
| ab5a3f9de3 | |||
| eb3da8cb03 | |||
| 9e1ecd7124 | |||
| efbaf47dc7 | |||
| f10ecb2a8d | |||
| 6e81391711 | |||
| 0d64f4a2d5 | |||
| d63e5a60ae | |||
| 384f1344fd | |||
| add24915a3 | |||
| 089bbfc5cc | |||
| 1944b6a335 | |||
| b8cfe63fc6 | |||
| 9e091a2c92 | |||
| 41bcdc3356 | |||
| 40486676df | |||
| 6f2078cda3 | |||
| b8d2f2ba37 | |||
| 03491fcc09 | |||
| 571073fe1f | |||
| a577d5c5fa | |||
| 160814f425 | |||
| b83b36274a | |||
| f3db4306c2 | |||
| 5c7fb5d7ae | |||
| 0dfc1c4e7a | |||
| 3f151428b7 | |||
| 2606e4d641 | |||
| be25ea4f09 | |||
| 77959341a3 | |||
| 9f54bcc21b | |||
| 6d236b8169 | |||
| 09b894a4aa | |||
| 1e2b5e6991 | |||
| 496ec4bcca | |||
| 3e51d0b539 | |||
| c31a291a9c | |||
| 96938bb33c | |||
| e7b1682a4e | |||
| d191635fd8 | |||
| bdd945c1c4 | |||
| 6ccf63dae2 | |||
| 987282da78 | |||
| 56186232f3 | |||
| fb2da6be9a | |||
| 8796187389 | |||
| edff53609f | |||
| dbc91c1d48 | |||
| 0607c8f4b4 | |||
| 7ccb6b960c | |||
| 561a78bef3 | |||
| 9876a2a081 | |||
| fba5becd90 | |||
| d5179b4bdc | |||
| ff8f22854c | |||
| 110d721c76 | |||
| 8c010c8df4 | |||
| 0ac1759395 | |||
| 07fb4ff243 | |||
| 2650d235ea | |||
| 9e89197284 | |||
| 8159d36114 | |||
| cf4f4ce8c7 | |||
| 9a1883bb49 | |||
| 8e16a443e5 | |||
| 35411cd57e | |||
| 845926236e | |||
| eae07c070a | |||
| 659226886f | |||
| 1e52d5c7f2 | |||
| 9463c84603 | |||
| 7cc707f1ce | |||
| 59524c7933 | |||
| 1d141566bd | |||
| ac41f3028c | |||
| 750ca79ac0 | |||
| 71bf707bcf | |||
| 31f1e1d7a4 | |||
| 361ab0f92b | |||
| e68a8f9c0f | |||
| 15770ff90f | |||
| 618ebfe43c | |||
| ff15fea9f8 | |||
| 2872c89f0c | |||
| 2dc9bc98f7 | |||
| 72d7e6e9dd | |||
| f912daf4b2 | |||
| d9fc2a8bf6 | |||
| 45fe37a301 | |||
| ef76047ba2 | |||
| d475e5362b | |||
| 3027b4a5a8 | |||
| 3829abbd2d | |||
| e6e3b37a62 | |||
| ce501ae627 | |||
| b6f954e082 | |||
| b368388714 | |||
| 8842e4e94f | |||
| 0ed608abff | |||
| afcf3eaac3 |
+29
-6
@@ -5,9 +5,14 @@ omit =
|
||||
homeassistant/__main__.py
|
||||
|
||||
# omit pieces of code that rely on external devices being present
|
||||
homeassistant/components/alarm_control_panel/alarmdotcom.py
|
||||
|
||||
homeassistant/components/arduino.py
|
||||
homeassistant/components/*/arduino.py
|
||||
|
||||
homeassistant/components/insteon_hub.py
|
||||
homeassistant/components/*/insteon_hub.py
|
||||
|
||||
homeassistant/components/isy994.py
|
||||
homeassistant/components/*/isy994.py
|
||||
|
||||
@@ -15,6 +20,10 @@ omit =
|
||||
homeassistant/components/*/modbus.py
|
||||
|
||||
homeassistant/components/*/tellstick.py
|
||||
|
||||
homeassistant/components/tellduslive.py
|
||||
homeassistant/components/*/tellduslive.py
|
||||
|
||||
homeassistant/components/*/vera.py
|
||||
|
||||
homeassistant/components/ecobee.py
|
||||
@@ -26,12 +35,24 @@ omit =
|
||||
homeassistant/components/wink.py
|
||||
homeassistant/components/*/wink.py
|
||||
|
||||
homeassistant/components/zigbee.py
|
||||
homeassistant/components/*/zigbee.py
|
||||
|
||||
homeassistant/components/zwave.py
|
||||
homeassistant/components/*/zwave.py
|
||||
|
||||
homeassistant/components/rfxtrx.py
|
||||
homeassistant/components/*/rfxtrx.py
|
||||
|
||||
homeassistant/components/mysensors.py
|
||||
homeassistant/components/*/mysensors.py
|
||||
|
||||
homeassistant/components/nest.py
|
||||
homeassistant/components/*/nest.py
|
||||
|
||||
homeassistant/components/rpi_gpio.py
|
||||
homeassistant/components/*/rpi_gpio.py
|
||||
|
||||
homeassistant/components/binary_sensor/arest.py
|
||||
homeassistant/components/binary_sensor/rest.py
|
||||
homeassistant/components/browser.py
|
||||
@@ -41,12 +62,10 @@ omit =
|
||||
homeassistant/components/device_tracker/asuswrt.py
|
||||
homeassistant/components/device_tracker/ddwrt.py
|
||||
homeassistant/components/device_tracker/fritz.py
|
||||
homeassistant/components/device_tracker/geofancy.py
|
||||
homeassistant/components/device_tracker/icloud.py
|
||||
homeassistant/components/device_tracker/luci.py
|
||||
homeassistant/components/device_tracker/netgear.py
|
||||
homeassistant/components/device_tracker/nmap_tracker.py
|
||||
homeassistant/components/device_tracker/owntracks.py
|
||||
homeassistant/components/device_tracker/snmp.py
|
||||
homeassistant/components/device_tracker/thomson.py
|
||||
homeassistant/components/device_tracker/tomato.py
|
||||
@@ -55,11 +74,13 @@ omit =
|
||||
homeassistant/components/discovery.py
|
||||
homeassistant/components/downloader.py
|
||||
homeassistant/components/ifttt.py
|
||||
homeassistant/components/statsd.py
|
||||
homeassistant/components/influxdb.py
|
||||
homeassistant/components/keyboard.py
|
||||
homeassistant/components/light/blinksticklight.py
|
||||
homeassistant/components/light/hue.py
|
||||
homeassistant/components/light/hyperion.py
|
||||
homeassistant/components/light/lifx.py
|
||||
homeassistant/components/light/limitlessled.py
|
||||
homeassistant/components/media_player/cast.py
|
||||
homeassistant/components/media_player/denon.py
|
||||
@@ -70,6 +91,7 @@ omit =
|
||||
homeassistant/components/media_player/plex.py
|
||||
homeassistant/components/media_player/sonos.py
|
||||
homeassistant/components/media_player/squeezebox.py
|
||||
homeassistant/components/notify/free_mobile.py
|
||||
homeassistant/components/notify/instapush.py
|
||||
homeassistant/components/notify/nma.py
|
||||
homeassistant/components/notify/pushbullet.py
|
||||
@@ -79,7 +101,9 @@ omit =
|
||||
homeassistant/components/notify/smtp.py
|
||||
homeassistant/components/notify/syslog.py
|
||||
homeassistant/components/notify/telegram.py
|
||||
homeassistant/components/notify/twitter.py
|
||||
homeassistant/components/notify/xmpp.py
|
||||
homeassistant/components/notify/googlevoice.py
|
||||
homeassistant/components/sensor/arest.py
|
||||
homeassistant/components/sensor/bitcoin.py
|
||||
homeassistant/components/sensor/cpuspeed.py
|
||||
@@ -89,10 +113,10 @@ omit =
|
||||
homeassistant/components/sensor/eliqonline.py
|
||||
homeassistant/components/sensor/forecast.py
|
||||
homeassistant/components/sensor/glances.py
|
||||
homeassistant/components/sensor/mysensors.py
|
||||
homeassistant/components/sensor/netatmo.py
|
||||
homeassistant/components/sensor/onewire.py
|
||||
homeassistant/components/sensor/openweathermap.py
|
||||
homeassistant/components/sensor/rest.py
|
||||
homeassistant/components/sensor/rpi_gpio.py
|
||||
homeassistant/components/sensor/sabnzbd.py
|
||||
homeassistant/components/sensor/swiss_public_transport.py
|
||||
homeassistant/components/sensor/systemmonitor.py
|
||||
@@ -108,13 +132,12 @@ omit =
|
||||
homeassistant/components/switch/mystrom.py
|
||||
homeassistant/components/switch/orvibo.py
|
||||
homeassistant/components/switch/rest.py
|
||||
homeassistant/components/switch/rpi_gpio.py
|
||||
homeassistant/components/switch/transmission.py
|
||||
homeassistant/components/switch/wemo.py
|
||||
homeassistant/components/thermostat/heatmiser.py
|
||||
homeassistant/components/thermostat/homematic.py
|
||||
homeassistant/components/thermostat/honeywell.py
|
||||
homeassistant/components/thermostat/nest.py
|
||||
homeassistant/components/thermostat/proliphix.py
|
||||
homeassistant/components/thermostat/radiotherm.py
|
||||
|
||||
|
||||
|
||||
+11
@@ -41,6 +41,7 @@ Icon
|
||||
dist
|
||||
build
|
||||
eggs
|
||||
.eggs
|
||||
parts
|
||||
bin
|
||||
var
|
||||
@@ -68,6 +69,16 @@ nosetests.xml
|
||||
|
||||
.python-version
|
||||
|
||||
# emacs auto backups
|
||||
*~
|
||||
*#
|
||||
*.orig
|
||||
|
||||
# venv stuff
|
||||
pyvenv.cfg
|
||||
pip-selfcheck.json
|
||||
venv
|
||||
|
||||
# vimmy stuff
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
+1
-3
@@ -8,9 +8,7 @@ python:
|
||||
- 3.4
|
||||
- 3.5
|
||||
install:
|
||||
# Validate requirements_all.txt on Python 3.5
|
||||
- if [[ $TRAVIS_PYTHON_VERSION == '3.5' ]]; then python3 setup.py develop; script/gen_requirements_all.py validate; fi
|
||||
- script/bootstrap_server
|
||||
- "true"
|
||||
script:
|
||||
- script/cibuild
|
||||
matrix:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Paulus Schoutsen
|
||||
Copyright (c) 2016 Paulus Schoutsen
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
|
||||
@@ -29,9 +29,13 @@ import time
|
||||
import logging
|
||||
|
||||
from homeassistant.const import STATE_HOME, STATE_NOT_HOME, STATE_ON, STATE_OFF
|
||||
import homeassistant.loader as loader
|
||||
from homeassistant.helpers import validate_config
|
||||
from homeassistant.helpers.event_decorators import \
|
||||
track_state_change, track_time_change
|
||||
from homeassistant.helpers.service import service
|
||||
import homeassistant.components as core
|
||||
from homeassistant.components import device_tracker
|
||||
from homeassistant.components import light
|
||||
|
||||
# The domain of your component. Should be equal to the name of your component
|
||||
DOMAIN = "example"
|
||||
@@ -39,11 +43,14 @@ DOMAIN = "example"
|
||||
# List of component names (string) your component depends upon
|
||||
# We depend on group because group will be loaded after all the components that
|
||||
# initialize devices have been setup.
|
||||
DEPENDENCIES = ['group']
|
||||
DEPENDENCIES = ['group', 'device_tracker', 'light']
|
||||
|
||||
# Configuration key for the entity id we are targetting
|
||||
CONF_TARGET = 'target'
|
||||
|
||||
# Variable for storing configuration parameters
|
||||
TARGET_ID = None
|
||||
|
||||
# Name of the service that we expose
|
||||
SERVICE_FLASH = 'flash'
|
||||
|
||||
@@ -53,84 +60,89 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
def setup(hass, config):
|
||||
""" Setup example component. """
|
||||
global TARGET_ID
|
||||
|
||||
# Validate that all required config options are given
|
||||
if not validate_config(config, {DOMAIN: [CONF_TARGET]}, _LOGGER):
|
||||
return False
|
||||
|
||||
target_id = config[DOMAIN][CONF_TARGET]
|
||||
TARGET_ID = config[DOMAIN][CONF_TARGET]
|
||||
|
||||
# Validate that the target entity id exists
|
||||
if hass.states.get(target_id) is None:
|
||||
_LOGGER.error("Target entity id %s does not exist", target_id)
|
||||
if hass.states.get(TARGET_ID) is None:
|
||||
_LOGGER.error("Target entity id %s does not exist",
|
||||
TARGET_ID)
|
||||
|
||||
# Tell the bootstrapper that we failed to initialize
|
||||
# Tell the bootstrapper that we failed to initialize and clear the
|
||||
# stored target id so our functions don't run.
|
||||
TARGET_ID = None
|
||||
return False
|
||||
|
||||
# We will use the component helper methods to check the states.
|
||||
device_tracker = loader.get_component('device_tracker')
|
||||
light = loader.get_component('light')
|
||||
|
||||
def track_devices(entity_id, old_state, new_state):
|
||||
""" Called when the group.all devices change state. """
|
||||
|
||||
# If anyone comes home and the core is not on, turn it on.
|
||||
if new_state.state == STATE_HOME and not core.is_on(hass, target_id):
|
||||
|
||||
core.turn_on(hass, target_id)
|
||||
|
||||
# If all people leave the house and the core is on, turn it off
|
||||
elif new_state.state == STATE_NOT_HOME and core.is_on(hass, target_id):
|
||||
|
||||
core.turn_off(hass, target_id)
|
||||
|
||||
# Register our track_devices method to receive state changes of the
|
||||
# all tracked devices group.
|
||||
hass.states.track_change(
|
||||
device_tracker.ENTITY_ID_ALL_DEVICES, track_devices)
|
||||
|
||||
def wake_up(now):
|
||||
""" Turn it on in the morning if there are people home and
|
||||
it is not already on. """
|
||||
|
||||
if device_tracker.is_on(hass) and not core.is_on(hass, target_id):
|
||||
_LOGGER.info('People home at 7AM, turning it on')
|
||||
core.turn_on(hass, target_id)
|
||||
|
||||
# Register our wake_up service to be called at 7AM in the morning
|
||||
hass.track_time_change(wake_up, hour=7, minute=0, second=0)
|
||||
|
||||
def all_lights_off(entity_id, old_state, new_state):
|
||||
""" If all lights turn off, turn off. """
|
||||
|
||||
if core.is_on(hass, target_id):
|
||||
_LOGGER.info('All lights have been turned off, turning it off')
|
||||
core.turn_off(hass, target_id)
|
||||
|
||||
# Register our all_lights_off method to be called when all lights turn off
|
||||
hass.states.track_change(
|
||||
light.ENTITY_ID_ALL_LIGHTS, all_lights_off, STATE_ON, STATE_OFF)
|
||||
|
||||
def flash_service(call):
|
||||
""" Service that will turn the target off for 10 seconds
|
||||
if on and vice versa. """
|
||||
|
||||
if core.is_on(hass, target_id):
|
||||
core.turn_off(hass, target_id)
|
||||
|
||||
time.sleep(10)
|
||||
|
||||
core.turn_on(hass, target_id)
|
||||
|
||||
else:
|
||||
core.turn_on(hass, target_id)
|
||||
|
||||
time.sleep(10)
|
||||
|
||||
core.turn_off(hass, target_id)
|
||||
|
||||
# Register our service with HASS.
|
||||
hass.services.register(DOMAIN, SERVICE_FLASH, flash_service)
|
||||
|
||||
# Tells the bootstrapper that the component was successfully initialized
|
||||
# Tell the bootstrapper that we initialized successfully
|
||||
return True
|
||||
|
||||
|
||||
@track_state_change(device_tracker.ENTITY_ID_ALL_DEVICES)
|
||||
def track_devices(hass, entity_id, old_state, new_state):
|
||||
""" Called when the group.all devices change state. """
|
||||
# If the target id is not set, return
|
||||
if not TARGET_ID:
|
||||
return
|
||||
|
||||
# If anyone comes home and the entity is not on, turn it on.
|
||||
if new_state.state == STATE_HOME and not core.is_on(hass, TARGET_ID):
|
||||
|
||||
core.turn_on(hass, TARGET_ID)
|
||||
|
||||
# If all people leave the house and the entity is on, turn it off
|
||||
elif new_state.state == STATE_NOT_HOME and core.is_on(hass, TARGET_ID):
|
||||
|
||||
core.turn_off(hass, TARGET_ID)
|
||||
|
||||
|
||||
@track_time_change(hour=7, minute=0, second=0)
|
||||
def wake_up(hass, now):
|
||||
"""
|
||||
Turn it on in the morning (7 AM) if there are people home and
|
||||
it is not already on.
|
||||
"""
|
||||
if not TARGET_ID:
|
||||
return
|
||||
|
||||
if device_tracker.is_on(hass) and not core.is_on(hass, TARGET_ID):
|
||||
_LOGGER.info('People home at 7AM, turning it on')
|
||||
core.turn_on(hass, TARGET_ID)
|
||||
|
||||
|
||||
@track_state_change(light.ENTITY_ID_ALL_LIGHTS, STATE_ON, STATE_OFF)
|
||||
def all_lights_off(hass, entity_id, old_state, new_state):
|
||||
""" If all lights turn off, turn off. """
|
||||
if not TARGET_ID:
|
||||
return
|
||||
|
||||
if core.is_on(hass, TARGET_ID):
|
||||
_LOGGER.info('All lights have been turned off, turning it off')
|
||||
core.turn_off(hass, TARGET_ID)
|
||||
|
||||
|
||||
@service(DOMAIN, SERVICE_FLASH)
|
||||
def flash_service(hass, call):
|
||||
"""
|
||||
Service that will turn the target off for 10 seconds if on and vice versa.
|
||||
"""
|
||||
if not TARGET_ID:
|
||||
return
|
||||
|
||||
if core.is_on(hass, TARGET_ID):
|
||||
core.turn_off(hass, TARGET_ID)
|
||||
|
||||
time.sleep(10)
|
||||
|
||||
core.turn_on(hass, TARGET_ID)
|
||||
|
||||
else:
|
||||
core.turn_on(hass, TARGET_ID)
|
||||
|
||||
time.sleep(10)
|
||||
|
||||
core.turn_off(hass, TARGET_ID)
|
||||
|
||||
@@ -24,6 +24,7 @@ import homeassistant.config as config_util
|
||||
import homeassistant.loader as loader
|
||||
import homeassistant.components as core_components
|
||||
import homeassistant.components.group as group
|
||||
from homeassistant.helpers import event_decorators, service
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.const import (
|
||||
__version__, EVENT_COMPONENT_LOADED, CONF_LATITUDE, CONF_LONGITUDE,
|
||||
@@ -199,6 +200,10 @@ def from_config_dict(config, hass=None, config_dir=None, enable_log=True,
|
||||
|
||||
_LOGGER.info('Home Assistant core initialized')
|
||||
|
||||
# give event decorators access to HASS
|
||||
event_decorators.HASS = hass
|
||||
service.HASS = hass
|
||||
|
||||
# Setup the components
|
||||
for domain in loader.load_order_components(components):
|
||||
_setup_component(hass, domain, config)
|
||||
@@ -223,7 +228,7 @@ def from_config_file(config_path, hass=None, verbose=False, daemon=False,
|
||||
|
||||
enable_logging(hass, verbose, daemon, log_rotate_days)
|
||||
|
||||
config_dict = config_util.load_config_file(config_path)
|
||||
config_dict = config_util.load_yaml_config_file(config_path)
|
||||
|
||||
return from_config_dict(config_dict, hass, enable_log=False,
|
||||
skip_pip=skip_pip)
|
||||
@@ -275,7 +280,7 @@ def enable_logging(hass, verbose=False, daemon=False, log_rotate_days=None):
|
||||
datefmt='%y-%m-%d %H:%M:%S'))
|
||||
logger = logging.getLogger('')
|
||||
logger.addHandler(err_handler)
|
||||
logger.setLevel(logging.NOTSET) # this sets the minimum log level
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
else:
|
||||
_LOGGER.error(
|
||||
|
||||
@@ -16,11 +16,11 @@ import itertools as it
|
||||
import logging
|
||||
|
||||
import homeassistant.core as ha
|
||||
import homeassistant.util as util
|
||||
from homeassistant.helpers import extract_entity_ids
|
||||
from homeassistant.helpers.entity import split_entity_id
|
||||
from homeassistant.helpers.service import extract_entity_ids
|
||||
from homeassistant.loader import get_component
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TURN_OFF)
|
||||
ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -36,7 +36,7 @@ def is_on(hass, entity_id=None):
|
||||
entity_ids = hass.states.entity_ids()
|
||||
|
||||
for entity_id in entity_ids:
|
||||
domain = util.split_entity_id(entity_id)[0]
|
||||
domain = split_entity_id(entity_id)[0]
|
||||
|
||||
module = get_component(domain)
|
||||
|
||||
@@ -68,6 +68,14 @@ def turn_off(hass, entity_id=None, **service_data):
|
||||
hass.services.call(ha.DOMAIN, SERVICE_TURN_OFF, service_data)
|
||||
|
||||
|
||||
def toggle(hass, entity_id=None, **service_data):
|
||||
""" Toggles specified entity. """
|
||||
if entity_id is not None:
|
||||
service_data[ATTR_ENTITY_ID] = entity_id
|
||||
|
||||
hass.services.call(ha.DOMAIN, SERVICE_TOGGLE, service_data)
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
""" Setup general services related to homeassistant. """
|
||||
|
||||
@@ -84,18 +92,27 @@ def setup(hass, config):
|
||||
|
||||
# Group entity_ids by domain. groupby requires sorted data.
|
||||
by_domain = it.groupby(sorted(entity_ids),
|
||||
lambda item: util.split_entity_id(item)[0])
|
||||
lambda item: split_entity_id(item)[0])
|
||||
|
||||
for domain, ent_ids in by_domain:
|
||||
# We want to block for all calls and only return when all calls
|
||||
# have been processed. If a service does not exist it causes a 10
|
||||
# second delay while we're blocking waiting for a response.
|
||||
# But services can be registered on other HA instances that are
|
||||
# listening to the bus too. So as a in between solution, we'll
|
||||
# block only if the service is defined in the current HA instance.
|
||||
blocking = hass.services.has_service(domain, service.service)
|
||||
|
||||
# Create a new dict for this call
|
||||
data = dict(service.data)
|
||||
|
||||
# ent_ids is a generator, convert it to a list.
|
||||
data[ATTR_ENTITY_ID] = list(ent_ids)
|
||||
|
||||
hass.services.call(domain, service.service, data, True)
|
||||
hass.services.call(domain, service.service, data, blocking)
|
||||
|
||||
hass.services.register(ha.DOMAIN, SERVICE_TURN_OFF, handle_turn_service)
|
||||
hass.services.register(ha.DOMAIN, SERVICE_TURN_ON, handle_turn_service)
|
||||
hass.services.register(ha.DOMAIN, SERVICE_TOGGLE, handle_turn_service)
|
||||
|
||||
return True
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
"""
|
||||
homeassistant.components.alarm_control_panel.alarmdotcom
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Interfaces with Verisure alarm control panel.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/alarm_control_panel.alarmdotcom/
|
||||
"""
|
||||
import logging
|
||||
|
||||
import homeassistant.components.alarm_control_panel as alarm
|
||||
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD
|
||||
|
||||
from homeassistant.const import (
|
||||
STATE_UNKNOWN,
|
||||
STATE_ALARM_DISARMED, STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_AWAY)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
REQUIREMENTS = ['https://github.com/Xorso/pyalarmdotcom'
|
||||
'/archive/0.0.7.zip'
|
||||
'#pyalarmdotcom==0.0.7']
|
||||
DEFAULT_NAME = 'Alarm.com'
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Setup an Alarm.com control panel. """
|
||||
|
||||
username = config.get(CONF_USERNAME)
|
||||
password = config.get(CONF_PASSWORD)
|
||||
|
||||
if username is None or password is None:
|
||||
_LOGGER.error('Must specify username and password!')
|
||||
return False
|
||||
|
||||
add_devices([AlarmDotCom(hass,
|
||||
config.get('name', DEFAULT_NAME),
|
||||
config.get('code'),
|
||||
username,
|
||||
password)])
|
||||
|
||||
|
||||
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
||||
# pylint: disable=abstract-method
|
||||
class AlarmDotCom(alarm.AlarmControlPanel):
|
||||
""" Represents a Alarm.com status. """
|
||||
|
||||
def __init__(self, hass, name, code, username, password):
|
||||
from pyalarmdotcom.pyalarmdotcom import Alarmdotcom
|
||||
self._alarm = Alarmdotcom(username, password, timeout=10)
|
||||
self._hass = hass
|
||||
self._name = name
|
||||
self._code = str(code) if code else None
|
||||
self._username = username
|
||||
self._password = password
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def code_format(self):
|
||||
""" One or more characters if code is defined. """
|
||||
return None if self._code is None else '.+'
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
""" Returns the state of the device. """
|
||||
if self._alarm.state == 'Disarmed':
|
||||
return STATE_ALARM_DISARMED
|
||||
elif self._alarm.state == 'Armed Stay':
|
||||
return STATE_ALARM_ARMED_HOME
|
||||
elif self._alarm.state == 'Armed Away':
|
||||
return STATE_ALARM_ARMED_AWAY
|
||||
else:
|
||||
return STATE_UNKNOWN
|
||||
|
||||
def alarm_disarm(self, code=None):
|
||||
""" Send disarm command. """
|
||||
if not self._validate_code(code, 'arming home'):
|
||||
return
|
||||
from pyalarmdotcom.pyalarmdotcom import Alarmdotcom
|
||||
# Open another session to alarm.com to fire off the command
|
||||
_alarm = Alarmdotcom(self._username, self._password, timeout=10)
|
||||
_alarm.disarm()
|
||||
self.update_ha_state()
|
||||
|
||||
def alarm_arm_home(self, code=None):
|
||||
""" Send arm home command. """
|
||||
if not self._validate_code(code, 'arming home'):
|
||||
return
|
||||
from pyalarmdotcom.pyalarmdotcom import Alarmdotcom
|
||||
# Open another session to alarm.com to fire off the command
|
||||
_alarm = Alarmdotcom(self._username, self._password, timeout=10)
|
||||
_alarm.arm_stay()
|
||||
self.update_ha_state()
|
||||
|
||||
def alarm_arm_away(self, code=None):
|
||||
""" Send arm away command. """
|
||||
if not self._validate_code(code, 'arming home'):
|
||||
return
|
||||
from pyalarmdotcom.pyalarmdotcom import Alarmdotcom
|
||||
# Open another session to alarm.com to fire off the command
|
||||
_alarm = Alarmdotcom(self._username, self._password, timeout=10)
|
||||
_alarm.arm_away()
|
||||
self.update_ha_state()
|
||||
|
||||
def _validate_code(self, code, state):
|
||||
""" Validate given code. """
|
||||
check = self._code is None or code == self._code
|
||||
if not check:
|
||||
_LOGGER.warning('Wrong code entered for %s', state)
|
||||
return check
|
||||
@@ -68,7 +68,8 @@ class ManualAlarm(alarm.AlarmControlPanel):
|
||||
@property
|
||||
def state(self):
|
||||
""" Returns the state of the device. """
|
||||
if self._state in (STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_AWAY) and \
|
||||
if self._state in (STATE_ALARM_ARMED_HOME,
|
||||
STATE_ALARM_ARMED_AWAY) and \
|
||||
self._pending_time and self._state_ts + self._pending_time > \
|
||||
dt_util.utcnow():
|
||||
return STATE_ALARM_PENDING
|
||||
|
||||
@@ -29,7 +29,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
|
||||
alarms.extend([
|
||||
VerisureAlarm(value)
|
||||
for value in verisure.get_alarm_status().values()
|
||||
for value in verisure.ALARM_STATUS.values()
|
||||
if verisure.SHOW_ALARM
|
||||
])
|
||||
|
||||
@@ -42,7 +42,6 @@ class VerisureAlarm(alarm.AlarmControlPanel):
|
||||
|
||||
def __init__(self, alarm_status):
|
||||
self._id = alarm_status.id
|
||||
self._device = verisure.MY_PAGES.DEVICE_ALARM
|
||||
self._state = STATE_UNKNOWN
|
||||
|
||||
@property
|
||||
@@ -58,40 +57,40 @@ class VerisureAlarm(alarm.AlarmControlPanel):
|
||||
@property
|
||||
def code_format(self):
|
||||
""" Four digit code required. """
|
||||
return '^\\d{4}$'
|
||||
return '^\\d{%s}$' % verisure.CODE_DIGITS
|
||||
|
||||
def update(self):
|
||||
""" Update alarm status """
|
||||
verisure.update()
|
||||
verisure.update_alarm()
|
||||
|
||||
if verisure.STATUS[self._device][self._id].status == 'unarmed':
|
||||
if verisure.ALARM_STATUS[self._id].status == 'unarmed':
|
||||
self._state = STATE_ALARM_DISARMED
|
||||
elif verisure.STATUS[self._device][self._id].status == 'armedhome':
|
||||
elif verisure.ALARM_STATUS[self._id].status == 'armedhome':
|
||||
self._state = STATE_ALARM_ARMED_HOME
|
||||
elif verisure.STATUS[self._device][self._id].status == 'armedaway':
|
||||
elif verisure.ALARM_STATUS[self._id].status == 'armed':
|
||||
self._state = STATE_ALARM_ARMED_AWAY
|
||||
elif verisure.STATUS[self._device][self._id].status != 'pending':
|
||||
elif verisure.ALARM_STATUS[self._id].status != 'pending':
|
||||
_LOGGER.error(
|
||||
'Unknown alarm state %s',
|
||||
verisure.STATUS[self._device][self._id].status)
|
||||
verisure.ALARM_STATUS[self._id].status)
|
||||
|
||||
def alarm_disarm(self, code=None):
|
||||
""" Send disarm command. """
|
||||
verisure.MY_PAGES.set_alarm_status(
|
||||
code,
|
||||
verisure.MY_PAGES.ALARM_DISARMED)
|
||||
_LOGGER.warning('disarming')
|
||||
verisure.MY_PAGES.alarm.set(code, 'DISARMED')
|
||||
_LOGGER.info('verisure alarm disarming')
|
||||
verisure.MY_PAGES.alarm.wait_while_pending()
|
||||
verisure.update_alarm()
|
||||
|
||||
def alarm_arm_home(self, code=None):
|
||||
""" Send arm home command. """
|
||||
verisure.MY_PAGES.set_alarm_status(
|
||||
code,
|
||||
verisure.MY_PAGES.ALARM_ARMED_HOME)
|
||||
_LOGGER.warning('arming home')
|
||||
verisure.MY_PAGES.alarm.set(code, 'ARMED_HOME')
|
||||
_LOGGER.info('verisure alarm arming home')
|
||||
verisure.MY_PAGES.alarm.wait_while_pending()
|
||||
verisure.update_alarm()
|
||||
|
||||
def alarm_arm_away(self, code=None):
|
||||
""" Send arm away command. """
|
||||
verisure.MY_PAGES.set_alarm_status(
|
||||
code,
|
||||
verisure.MY_PAGES.ALARM_ARMED_AWAY)
|
||||
_LOGGER.warning('arming away')
|
||||
verisure.MY_PAGES.alarm.set(code, 'ARMED_AWAY')
|
||||
_LOGGER.info('verisure alarm arming away')
|
||||
verisure.MY_PAGES.alarm.wait_while_pending()
|
||||
verisure.update_alarm()
|
||||
|
||||
@@ -11,6 +11,7 @@ import logging
|
||||
|
||||
from homeassistant.const import HTTP_OK, HTTP_UNPROCESSABLE_ENTITY
|
||||
from homeassistant.util import template
|
||||
from homeassistant.helpers.service import call_from_config
|
||||
|
||||
DOMAIN = 'alexa'
|
||||
DEPENDENCIES = ['http']
|
||||
@@ -23,6 +24,7 @@ API_ENDPOINT = '/api/alexa'
|
||||
CONF_INTENTS = 'intents'
|
||||
CONF_CARD = 'card'
|
||||
CONF_SPEECH = 'speech'
|
||||
CONF_ACTION = 'action'
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
@@ -80,6 +82,7 @@ def _handle_alexa(handler, path_match, data):
|
||||
|
||||
speech = config.get(CONF_SPEECH)
|
||||
card = config.get(CONF_CARD)
|
||||
action = config.get(CONF_ACTION)
|
||||
|
||||
# pylint: disable=unsubscriptable-object
|
||||
if speech is not None:
|
||||
@@ -89,6 +92,9 @@ def _handle_alexa(handler, path_match, data):
|
||||
response.add_card(CardType[card['type']], card['title'],
|
||||
card['content'])
|
||||
|
||||
if action is not None:
|
||||
call_from_config(handler.server.hass, action, True)
|
||||
|
||||
handler.write_json(response.as_dict())
|
||||
|
||||
|
||||
@@ -116,7 +122,7 @@ class AlexaResponse(object):
|
||||
self.should_end_session = True
|
||||
if intent is not None and 'slots' in intent:
|
||||
self.variables = {key: value['value'] for key, value
|
||||
in intent['slots'].items()}
|
||||
in intent['slots'].items() if 'value' in value}
|
||||
else:
|
||||
self.variables = {}
|
||||
|
||||
|
||||
@@ -9,11 +9,6 @@ https://home-assistant.io/components/arduino/
|
||||
"""
|
||||
import logging
|
||||
|
||||
try:
|
||||
from PyMata.pymata import PyMata
|
||||
except ImportError:
|
||||
PyMata = None
|
||||
|
||||
from homeassistant.helpers import validate_config
|
||||
from homeassistant.const import (EVENT_HOMEASSISTANT_START,
|
||||
EVENT_HOMEASSISTANT_STOP)
|
||||
@@ -27,18 +22,12 @@ _LOGGER = logging.getLogger(__name__)
|
||||
def setup(hass, config):
|
||||
""" Setup the Arduino component. """
|
||||
|
||||
global PyMata # pylint: disable=invalid-name
|
||||
if PyMata is None:
|
||||
from PyMata.pymata import PyMata as PyMata_
|
||||
PyMata = PyMata_
|
||||
|
||||
import serial
|
||||
|
||||
if not validate_config(config,
|
||||
{DOMAIN: ['port']},
|
||||
_LOGGER):
|
||||
return False
|
||||
|
||||
import serial
|
||||
global BOARD
|
||||
try:
|
||||
BOARD = ArduinoBoard(config[DOMAIN]['port'])
|
||||
@@ -67,6 +56,7 @@ class ArduinoBoard(object):
|
||||
""" Represents an Arduino board. """
|
||||
|
||||
def __init__(self, port):
|
||||
from PyMata.pymata import PyMata
|
||||
self._port = port
|
||||
self._board = PyMata(self._port, verbose=False)
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@ https://home-assistant.io/components/automation/
|
||||
import logging
|
||||
|
||||
from homeassistant.bootstrap import prepare_setup_platform
|
||||
from homeassistant.util import split_entity_id
|
||||
from homeassistant.const import ATTR_ENTITY_ID, CONF_PLATFORM
|
||||
from homeassistant.const import CONF_PLATFORM
|
||||
from homeassistant.components import logbook
|
||||
from homeassistant.helpers.service import call_from_config
|
||||
|
||||
DOMAIN = 'automation'
|
||||
|
||||
@@ -19,8 +19,6 @@ DEPENDENCIES = ['group']
|
||||
|
||||
CONF_ALIAS = 'alias'
|
||||
CONF_SERVICE = 'service'
|
||||
CONF_SERVICE_ENTITY_ID = 'entity_id'
|
||||
CONF_SERVICE_DATA = 'data'
|
||||
|
||||
CONF_CONDITION = 'condition'
|
||||
CONF_ACTION = 'action'
|
||||
@@ -96,22 +94,7 @@ def _get_action(hass, config, name):
|
||||
_LOGGER.info('Executing %s', name)
|
||||
logbook.log_entry(hass, name, 'has been triggered', DOMAIN)
|
||||
|
||||
domain, service = split_entity_id(config[CONF_SERVICE])
|
||||
service_data = config.get(CONF_SERVICE_DATA, {})
|
||||
|
||||
if not isinstance(service_data, dict):
|
||||
_LOGGER.error("%s should be a dictionary", CONF_SERVICE_DATA)
|
||||
service_data = {}
|
||||
|
||||
if CONF_SERVICE_ENTITY_ID in config:
|
||||
try:
|
||||
service_data[ATTR_ENTITY_ID] = \
|
||||
config[CONF_SERVICE_ENTITY_ID].split(",")
|
||||
except AttributeError:
|
||||
service_data[ATTR_ENTITY_ID] = \
|
||||
config[CONF_SERVICE_ENTITY_ID]
|
||||
|
||||
hass.services.call(domain, service, service_data)
|
||||
call_from_config(hass, config)
|
||||
|
||||
return action
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ Offers numeric state listening automation rules.
|
||||
For more details about this automation rule, please refer to the documentation
|
||||
at https://home-assistant.io/components/automation/#numeric-state-trigger
|
||||
"""
|
||||
from functools import partial
|
||||
import logging
|
||||
|
||||
from homeassistant.const import CONF_VALUE_TEMPLATE
|
||||
@@ -20,6 +21,14 @@ CONF_ABOVE = "above"
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _renderer(hass, value_template, state):
|
||||
"""Render state value."""
|
||||
if value_template is None:
|
||||
return state.state
|
||||
|
||||
return template.render(hass, value_template, {'state': state})
|
||||
|
||||
|
||||
def trigger(hass, config, action):
|
||||
""" Listen for state changes based on `config`. """
|
||||
entity_id = config.get(CONF_ENTITY_ID)
|
||||
@@ -38,12 +47,7 @@ def trigger(hass, config, action):
|
||||
CONF_BELOW, CONF_ABOVE)
|
||||
return False
|
||||
|
||||
if value_template is not None:
|
||||
renderer = lambda value: template.render(hass,
|
||||
value_template,
|
||||
{'state': value})
|
||||
else:
|
||||
renderer = lambda value: value.state
|
||||
renderer = partial(_renderer, hass, value_template)
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def state_automation_listener(entity, from_s, to_s):
|
||||
@@ -79,12 +83,7 @@ def if_action(hass, config):
|
||||
CONF_BELOW, CONF_ABOVE)
|
||||
return None
|
||||
|
||||
if value_template is not None:
|
||||
renderer = lambda value: template.render(hass,
|
||||
value_template,
|
||||
{'state': value})
|
||||
else:
|
||||
renderer = lambda value: value.state
|
||||
renderer = partial(_renderer, hass, value_template)
|
||||
|
||||
def if_numeric_state():
|
||||
""" Test numeric state condition. """
|
||||
|
||||
@@ -10,13 +10,17 @@ import logging
|
||||
from datetime import timedelta
|
||||
|
||||
from homeassistant.components import sun
|
||||
from homeassistant.helpers.event import track_point_in_utc_time
|
||||
from homeassistant.helpers.event import track_sunrise, track_sunset
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
DEPENDENCIES = ['sun']
|
||||
|
||||
CONF_OFFSET = 'offset'
|
||||
CONF_EVENT = 'event'
|
||||
CONF_BEFORE = "before"
|
||||
CONF_BEFORE_OFFSET = "before_offset"
|
||||
CONF_AFTER = "after"
|
||||
CONF_AFTER_OFFSET = "after_offset"
|
||||
|
||||
EVENT_SUNSET = 'sunset'
|
||||
EVENT_SUNRISE = 'sunrise'
|
||||
@@ -37,69 +41,108 @@ def trigger(hass, config, action):
|
||||
_LOGGER.error("Invalid value for %s: %s", CONF_EVENT, event)
|
||||
return False
|
||||
|
||||
if CONF_OFFSET in config:
|
||||
raw_offset = config.get(CONF_OFFSET)
|
||||
|
||||
negative_offset = False
|
||||
if raw_offset.startswith('-'):
|
||||
negative_offset = True
|
||||
raw_offset = raw_offset[1:]
|
||||
|
||||
try:
|
||||
(hour, minute, second) = [int(x) for x in raw_offset.split(':')]
|
||||
except ValueError:
|
||||
_LOGGER.error('Could not parse offset %s', raw_offset)
|
||||
return False
|
||||
|
||||
offset = timedelta(hours=hour, minutes=minute, seconds=second)
|
||||
|
||||
if negative_offset:
|
||||
offset *= -1
|
||||
else:
|
||||
offset = timedelta(0)
|
||||
offset = _parse_offset(config.get(CONF_OFFSET))
|
||||
if offset is False:
|
||||
return False
|
||||
|
||||
# Do something to call action
|
||||
if event == EVENT_SUNRISE:
|
||||
trigger_sunrise(hass, action, offset)
|
||||
track_sunrise(hass, action, offset)
|
||||
else:
|
||||
trigger_sunset(hass, action, offset)
|
||||
track_sunset(hass, action, offset)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def trigger_sunrise(hass, action, offset):
|
||||
""" Trigger action at next sun rise. """
|
||||
def next_rise():
|
||||
""" Returns next sunrise. """
|
||||
next_time = sun.next_rising_utc(hass) + offset
|
||||
def if_action(hass, config):
|
||||
""" Wraps action method with sun based condition. """
|
||||
before = config.get(CONF_BEFORE)
|
||||
after = config.get(CONF_AFTER)
|
||||
|
||||
while next_time < dt_util.utcnow():
|
||||
next_time = next_time + timedelta(days=1)
|
||||
# Make sure required configuration keys are present
|
||||
if before is None and after is None:
|
||||
logging.getLogger(__name__).error(
|
||||
"Missing if-condition configuration key %s or %s",
|
||||
CONF_BEFORE, CONF_AFTER)
|
||||
return None
|
||||
|
||||
return next_time
|
||||
# Make sure configuration keys have the right value
|
||||
if before not in (None, EVENT_SUNRISE, EVENT_SUNSET) or \
|
||||
after not in (None, EVENT_SUNRISE, EVENT_SUNSET):
|
||||
logging.getLogger(__name__).error(
|
||||
"%s and %s can only be set to %s or %s",
|
||||
CONF_BEFORE, CONF_AFTER, EVENT_SUNRISE, EVENT_SUNSET)
|
||||
return None
|
||||
|
||||
def sunrise_automation_listener(now):
|
||||
""" Called when it's time for action. """
|
||||
track_point_in_utc_time(hass, sunrise_automation_listener, next_rise())
|
||||
action()
|
||||
before_offset = _parse_offset(config.get(CONF_BEFORE_OFFSET))
|
||||
after_offset = _parse_offset(config.get(CONF_AFTER_OFFSET))
|
||||
if before_offset is False or after_offset is False:
|
||||
return None
|
||||
|
||||
track_point_in_utc_time(hass, sunrise_automation_listener, next_rise())
|
||||
if before is None:
|
||||
def before_func():
|
||||
"""Return no point in time."""
|
||||
return None
|
||||
elif before == EVENT_SUNRISE:
|
||||
def before_func():
|
||||
"""Return time before sunrise."""
|
||||
return sun.next_rising(hass) + before_offset
|
||||
else:
|
||||
def before_func():
|
||||
"""Return time before sunset."""
|
||||
return sun.next_setting(hass) + before_offset
|
||||
|
||||
if after is None:
|
||||
def after_func():
|
||||
"""Return no point in time."""
|
||||
return None
|
||||
elif after == EVENT_SUNRISE:
|
||||
def after_func():
|
||||
"""Return time after sunrise."""
|
||||
return sun.next_rising(hass) + after_offset
|
||||
else:
|
||||
def after_func():
|
||||
"""Return time after sunset."""
|
||||
return sun.next_setting(hass) + after_offset
|
||||
|
||||
def time_if():
|
||||
""" Validate time based if-condition """
|
||||
|
||||
now = dt_util.now()
|
||||
before = before_func()
|
||||
after = after_func()
|
||||
|
||||
if before is not None and now > now.replace(hour=before.hour,
|
||||
minute=before.minute):
|
||||
return False
|
||||
|
||||
if after is not None and now < now.replace(hour=after.hour,
|
||||
minute=after.minute):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
return time_if
|
||||
|
||||
|
||||
def trigger_sunset(hass, action, offset):
|
||||
""" Trigger action at next sun set. """
|
||||
def next_set():
|
||||
""" Returns next sunrise. """
|
||||
next_time = sun.next_setting_utc(hass) + offset
|
||||
def _parse_offset(raw_offset):
|
||||
if raw_offset is None:
|
||||
return timedelta(0)
|
||||
|
||||
while next_time < dt_util.utcnow():
|
||||
next_time = next_time + timedelta(days=1)
|
||||
negative_offset = False
|
||||
if raw_offset.startswith('-'):
|
||||
negative_offset = True
|
||||
raw_offset = raw_offset[1:]
|
||||
|
||||
return next_time
|
||||
try:
|
||||
(hour, minute, second) = [int(x) for x in raw_offset.split(':')]
|
||||
except ValueError:
|
||||
_LOGGER.error('Could not parse offset %s', raw_offset)
|
||||
return False
|
||||
|
||||
def sunset_automation_listener(now):
|
||||
""" Called when it's time for action. """
|
||||
track_point_in_utc_time(hass, sunset_automation_listener, next_set())
|
||||
action()
|
||||
offset = timedelta(hours=hour, minutes=minute, seconds=second)
|
||||
|
||||
track_point_in_utc_time(hass, sunset_automation_listener, next_set())
|
||||
if negative_offset:
|
||||
offset *= -1
|
||||
|
||||
return offset
|
||||
|
||||
@@ -8,7 +8,6 @@ at https://home-assistant.io/components/automation/#time-trigger
|
||||
"""
|
||||
import logging
|
||||
|
||||
from homeassistant.util import convert
|
||||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.helpers.event import track_time_change
|
||||
|
||||
@@ -32,11 +31,11 @@ def trigger(hass, config, action):
|
||||
_error_time(config[CONF_AFTER], CONF_AFTER)
|
||||
return False
|
||||
hours, minutes, seconds = after.hour, after.minute, after.second
|
||||
elif (CONF_HOURS in config or CONF_MINUTES in config
|
||||
or CONF_SECONDS in config):
|
||||
hours = convert(config.get(CONF_HOURS), int)
|
||||
minutes = convert(config.get(CONF_MINUTES), int)
|
||||
seconds = convert(config.get(CONF_SECONDS), int)
|
||||
elif (CONF_HOURS in config or CONF_MINUTES in config or
|
||||
CONF_SECONDS in config):
|
||||
hours = config.get(CONF_HOURS)
|
||||
minutes = config.get(CONF_MINUTES)
|
||||
seconds = config.get(CONF_SECONDS)
|
||||
else:
|
||||
_LOGGER.error('One of %s, %s, %s OR %s needs to be specified',
|
||||
CONF_HOURS, CONF_MINUTES, CONF_SECONDS, CONF_AFTER)
|
||||
@@ -59,7 +58,7 @@ def if_action(hass, config):
|
||||
weekday = config.get(CONF_WEEKDAY)
|
||||
|
||||
if before is None and after is None and weekday is None:
|
||||
logging.getLogger(__name__).error(
|
||||
_LOGGER.error(
|
||||
"Missing if-condition configuration key %s, %s or %s",
|
||||
CONF_BEFORE, CONF_AFTER, CONF_WEEKDAY)
|
||||
return None
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
"""
|
||||
homeassistant.components.binary_sensor.command_sensor
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Allows to configure custom shell commands to turn a value
|
||||
into a logical value for a binary sensor.
|
||||
"""
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
|
||||
from homeassistant.const import CONF_VALUE_TEMPLATE
|
||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||
from homeassistant.components.sensor.command_sensor import CommandSensorData
|
||||
from homeassistant.util import template
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_NAME = "Binary Command Sensor"
|
||||
DEFAULT_PAYLOAD_ON = 'ON'
|
||||
DEFAULT_PAYLOAD_OFF = 'OFF'
|
||||
|
||||
# Return cached results if last scan was less then this time ago
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Add the Command Sensor. """
|
||||
|
||||
if config.get('command') is None:
|
||||
_LOGGER.error('Missing required variable: "command"')
|
||||
return False
|
||||
|
||||
data = CommandSensorData(config.get('command'))
|
||||
|
||||
add_devices([CommandBinarySensor(
|
||||
hass,
|
||||
data,
|
||||
config.get('name', DEFAULT_NAME),
|
||||
config.get('payload_on', DEFAULT_PAYLOAD_ON),
|
||||
config.get('payload_off', DEFAULT_PAYLOAD_OFF),
|
||||
config.get(CONF_VALUE_TEMPLATE)
|
||||
)])
|
||||
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
class CommandBinarySensor(BinarySensorDevice):
|
||||
""" Represents a binary sensor that is returning
|
||||
a value of a shell commands. """
|
||||
def __init__(self, hass, data, name, payload_on,
|
||||
payload_off, value_template):
|
||||
self._hass = hass
|
||||
self.data = data
|
||||
self._name = name
|
||||
self._state = False
|
||||
self._payload_on = payload_on
|
||||
self._payload_off = payload_off
|
||||
self._value_template = value_template
|
||||
self.update()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" The name of the sensor. """
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
""" True if the binary sensor is on. """
|
||||
return self._state
|
||||
|
||||
def update(self):
|
||||
""" Gets the latest data and updates the state. """
|
||||
self.data.update()
|
||||
value = self.data.value
|
||||
|
||||
if self._value_template is not None:
|
||||
value = template.render_with_possible_json_value(
|
||||
self._hass, self._value_template, value, False)
|
||||
if value == self._payload_on:
|
||||
self._state = True
|
||||
elif value == self._payload_off:
|
||||
self._state = False
|
||||
@@ -0,0 +1,55 @@
|
||||
"""
|
||||
homeassistant.components.binary_sensor.nest
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Support for Nest Thermostat Binary Sensors.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/binary_sensor.nest/
|
||||
"""
|
||||
import logging
|
||||
import socket
|
||||
import homeassistant.components.nest as nest
|
||||
|
||||
from homeassistant.components.sensor.nest import NestSensor
|
||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||
|
||||
|
||||
BINARY_TYPES = ['fan',
|
||||
'hvac_ac_state',
|
||||
'hvac_aux_heater_state',
|
||||
'hvac_heat_x2_state',
|
||||
'hvac_heat_x3_state',
|
||||
'hvac_alt_heat_state',
|
||||
'hvac_alt_heat_x2_state',
|
||||
'hvac_emer_heat_state',
|
||||
'online']
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Setup Nest binary sensors. """
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
try:
|
||||
for structure in nest.NEST.structures:
|
||||
for device in structure.devices:
|
||||
for variable in config['monitored_conditions']:
|
||||
if variable in BINARY_TYPES:
|
||||
add_devices([NestBinarySensor(structure,
|
||||
device,
|
||||
variable)])
|
||||
else:
|
||||
logger.error('Nest sensor type: "%s" does not exist',
|
||||
variable)
|
||||
except socket.error:
|
||||
logger.error(
|
||||
"Connection error logging into the nest web service."
|
||||
)
|
||||
|
||||
|
||||
class NestBinarySensor(NestSensor, BinarySensorDevice):
|
||||
""" Represents a Nest binary sensor. """
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
""" True if the binary sensor is on. """
|
||||
return bool(getattr(self.device, self.variable))
|
||||
@@ -6,12 +6,11 @@ The rest binary sensor will consume responses sent by an exposed REST API.
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/binary_sensor.rest/
|
||||
"""
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
import requests
|
||||
|
||||
from homeassistant.const import CONF_VALUE_TEMPLATE
|
||||
from homeassistant.util import template, Throttle
|
||||
from homeassistant.util import template
|
||||
from homeassistant.components.sensor.rest import RestData
|
||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -19,61 +18,33 @@ _LOGGER = logging.getLogger(__name__)
|
||||
DEFAULT_NAME = 'REST Binary Sensor'
|
||||
DEFAULT_METHOD = 'GET'
|
||||
|
||||
# Return cached results if last scan was less then this time ago
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
|
||||
|
||||
|
||||
# pylint: disable=unused-variable
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Get the REST binary sensor. """
|
||||
|
||||
use_get = False
|
||||
use_post = False
|
||||
|
||||
"""Setup REST binary sensors."""
|
||||
resource = config.get('resource', None)
|
||||
method = config.get('method', DEFAULT_METHOD)
|
||||
payload = config.get('payload', None)
|
||||
verify_ssl = config.get('verify_ssl', True)
|
||||
|
||||
if method == 'GET':
|
||||
use_get = True
|
||||
elif method == 'POST':
|
||||
use_post = True
|
||||
rest = RestData(method, resource, payload, verify_ssl)
|
||||
rest.update()
|
||||
|
||||
try:
|
||||
if use_get:
|
||||
response = requests.get(resource, timeout=10, verify=verify_ssl)
|
||||
elif use_post:
|
||||
response = requests.post(resource, data=payload, timeout=10,
|
||||
verify=verify_ssl)
|
||||
if not response.ok:
|
||||
_LOGGER.error('Response status is "%s"', response.status_code)
|
||||
return False
|
||||
except requests.exceptions.MissingSchema:
|
||||
_LOGGER.error('Missing resource or schema in configuration. '
|
||||
'Add http:// to your URL.')
|
||||
return False
|
||||
except requests.exceptions.ConnectionError:
|
||||
_LOGGER.error('No route to resource/endpoint: %s',
|
||||
resource)
|
||||
if rest.data is None:
|
||||
_LOGGER.error('Unable to fetch Rest data')
|
||||
return False
|
||||
|
||||
if use_get:
|
||||
rest = RestDataGet(resource, verify_ssl)
|
||||
elif use_post:
|
||||
rest = RestDataPost(resource, payload, verify_ssl)
|
||||
|
||||
add_devices([RestBinarySensor(hass,
|
||||
rest,
|
||||
config.get('name', DEFAULT_NAME),
|
||||
config.get(CONF_VALUE_TEMPLATE))])
|
||||
add_devices([RestBinarySensor(
|
||||
hass, rest, config.get('name', DEFAULT_NAME),
|
||||
config.get(CONF_VALUE_TEMPLATE))])
|
||||
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
class RestBinarySensor(BinarySensorDevice):
|
||||
""" Implements a REST binary sensor. """
|
||||
"""REST binary sensor."""
|
||||
|
||||
def __init__(self, hass, rest, name, value_template):
|
||||
"""Initialize a REST binary sensor."""
|
||||
self._hass = hass
|
||||
self.rest = rest
|
||||
self._name = name
|
||||
@@ -83,63 +54,20 @@ class RestBinarySensor(BinarySensorDevice):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" The name of the binary sensor. """
|
||||
"""Name of the binary sensor."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
""" True if the binary sensor is on. """
|
||||
if self.rest.data is False:
|
||||
"""Return if the binary sensor is on."""
|
||||
if self.rest.data is None:
|
||||
return False
|
||||
else:
|
||||
if self._value_template is not None:
|
||||
self.rest.data = template.render_with_possible_json_value(
|
||||
self._hass, self._value_template, self.rest.data, False)
|
||||
return bool(int(self.rest.data))
|
||||
|
||||
if self._value_template is not None:
|
||||
self.rest.data = template.render_with_possible_json_value(
|
||||
self._hass, self._value_template, self.rest.data, False)
|
||||
return bool(int(self.rest.data))
|
||||
|
||||
def update(self):
|
||||
""" Gets the latest data from REST API and updates the state. """
|
||||
"""Get the latest data from REST API and updates the state."""
|
||||
self.rest.update()
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class RestDataGet(object):
|
||||
""" Class for handling the data retrieval with GET method. """
|
||||
|
||||
def __init__(self, resource, verify_ssl):
|
||||
self._resource = resource
|
||||
self._verify_ssl = verify_ssl
|
||||
self.data = False
|
||||
|
||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||
def update(self):
|
||||
""" Gets the latest data from REST service with GET method. """
|
||||
try:
|
||||
response = requests.get(self._resource, timeout=10,
|
||||
verify=self._verify_ssl)
|
||||
self.data = response.text
|
||||
except requests.exceptions.ConnectionError:
|
||||
_LOGGER.error("No route to resource/endpoint: %s", self._resource)
|
||||
self.data = False
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class RestDataPost(object):
|
||||
""" Class for handling the data retrieval with POST method. """
|
||||
|
||||
def __init__(self, resource, payload, verify_ssl):
|
||||
self._resource = resource
|
||||
self._payload = payload
|
||||
self._verify_ssl = verify_ssl
|
||||
self.data = False
|
||||
|
||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||
def update(self):
|
||||
""" Gets the latest data from REST service with POST method. """
|
||||
try:
|
||||
response = requests.post(self._resource, data=self._payload,
|
||||
timeout=10, verify=self._verify_ssl)
|
||||
self.data = response.text
|
||||
except requests.exceptions.ConnectionError:
|
||||
_LOGGER.error("No route to resource/endpoint: %s", self._resource)
|
||||
self.data = False
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
"""
|
||||
homeassistant.components.binary_sensor.rpi_gpio
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Allows to configure a binary sensor using RPi GPIO.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/binary_sensor.rpi_gpio/
|
||||
"""
|
||||
|
||||
import logging
|
||||
import homeassistant.components.rpi_gpio as rpi_gpio
|
||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||
from homeassistant.const import (DEVICE_DEFAULT_NAME)
|
||||
|
||||
DEFAULT_PULL_MODE = "UP"
|
||||
DEFAULT_BOUNCETIME = 50
|
||||
DEFAULT_INVERT_LOGIC = False
|
||||
|
||||
DEPENDENCIES = ['rpi_gpio']
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Sets up the Raspberry PI GPIO devices. """
|
||||
|
||||
pull_mode = config.get('pull_mode', DEFAULT_PULL_MODE)
|
||||
bouncetime = config.get('bouncetime', DEFAULT_BOUNCETIME)
|
||||
invert_logic = config.get('invert_logic', DEFAULT_INVERT_LOGIC)
|
||||
|
||||
binary_sensors = []
|
||||
ports = config.get('ports')
|
||||
for port_num, port_name in ports.items():
|
||||
binary_sensors.append(RPiGPIOBinarySensor(
|
||||
port_name, port_num, pull_mode, bouncetime, invert_logic))
|
||||
add_devices(binary_sensors)
|
||||
|
||||
|
||||
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
||||
class RPiGPIOBinarySensor(BinarySensorDevice):
|
||||
""" Represents a binary sensor that uses Raspberry Pi GPIO. """
|
||||
def __init__(self, name, port, pull_mode, bouncetime, invert_logic):
|
||||
# pylint: disable=no-member
|
||||
|
||||
self._name = name or DEVICE_DEFAULT_NAME
|
||||
self._port = port
|
||||
self._pull_mode = pull_mode
|
||||
self._bouncetime = bouncetime
|
||||
self._invert_logic = invert_logic
|
||||
|
||||
rpi_gpio.setup_input(self._port, self._pull_mode)
|
||||
self._state = rpi_gpio.read_input(self._port)
|
||||
|
||||
def read_gpio(port):
|
||||
""" Reads state from GPIO. """
|
||||
self._state = rpi_gpio.read_input(self._port)
|
||||
self.update_ha_state()
|
||||
rpi_gpio.edge_detect(self._port, read_gpio, self._bouncetime)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
""" No polling needed. """
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" The name of the sensor. """
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
""" Returns the state of the entity. """
|
||||
return self._state != self._invert_logic
|
||||
@@ -0,0 +1,29 @@
|
||||
"""
|
||||
homeassistant.components.binary_sensor.zigbee
|
||||
|
||||
Contains functionality to use a ZigBee device as a binary sensor.
|
||||
"""
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||
from homeassistant.components.zigbee import (
|
||||
ZigBeeDigitalIn, ZigBeeDigitalInConfig)
|
||||
|
||||
|
||||
DEPENDENCIES = ["zigbee"]
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""
|
||||
Create and add an entity based on the configuration.
|
||||
"""
|
||||
add_entities([
|
||||
ZigBeeBinarySensor(hass, ZigBeeDigitalInConfig(config))
|
||||
])
|
||||
|
||||
|
||||
class ZigBeeBinarySensor(ZigBeeDigitalIn, BinarySensorDevice):
|
||||
"""
|
||||
Use multiple inheritance to turn a ZigBeeDigitalIn into a
|
||||
BinarySensorDevice.
|
||||
"""
|
||||
pass
|
||||
@@ -11,7 +11,7 @@ the user has submitted configuration information.
|
||||
"""
|
||||
import logging
|
||||
|
||||
from homeassistant.helpers import generate_entity_id
|
||||
from homeassistant.helpers.entity import generate_entity_id
|
||||
from homeassistant.const import EVENT_TIME_CHANGED
|
||||
|
||||
DOMAIN = "configurator"
|
||||
|
||||
@@ -62,10 +62,16 @@ def setup(hass, config):
|
||||
lights = sorted(hass.states.entity_ids('light'))
|
||||
switches = sorted(hass.states.entity_ids('switch'))
|
||||
media_players = sorted(hass.states.entity_ids('media_player'))
|
||||
group.setup_group(hass, 'living room', [lights[2], lights[1], switches[0],
|
||||
media_players[1]])
|
||||
group.setup_group(hass, 'bedroom', [lights[0], switches[1],
|
||||
media_players[0]])
|
||||
group.Group(hass, 'living room', [
|
||||
lights[2], lights[1], switches[0], media_players[1],
|
||||
'scene.romantic_lights'])
|
||||
group.Group(hass, 'bedroom', [lights[0], switches[1],
|
||||
media_players[0]])
|
||||
group.Group(hass, 'Rooms', [
|
||||
'group.living_room', 'group.bedroom',
|
||||
'scene.romantic_lights', 'rollershutter.kitchen_window',
|
||||
'rollershutter.living_room_window',
|
||||
], view=True)
|
||||
|
||||
# Setup scripts
|
||||
bootstrap.setup_component(
|
||||
|
||||
@@ -229,7 +229,7 @@ class DeviceTracker(object):
|
||||
""" Initializes group for all tracked devices. """
|
||||
entity_ids = (dev.entity_id for dev in self.devices.values()
|
||||
if dev.track)
|
||||
self.group = group.setup_group(
|
||||
self.group = group.Group(
|
||||
self.hass, GROUP_NAME_ALL_DEVICES, entity_ids, False)
|
||||
|
||||
def update_stale(self, now):
|
||||
|
||||
@@ -58,8 +58,8 @@ class AsusWrtDeviceScanner(object):
|
||||
|
||||
def __init__(self, config):
|
||||
self.host = config[CONF_HOST]
|
||||
self.username = config[CONF_USERNAME]
|
||||
self.password = config[CONF_PASSWORD]
|
||||
self.username = str(config[CONF_USERNAME])
|
||||
self.password = str(config[CONF_PASSWORD])
|
||||
|
||||
self.lock = threading.Lock()
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ from homeassistant.helpers import validate_config
|
||||
from homeassistant.util import Throttle
|
||||
from homeassistant.components.device_tracker import DOMAIN
|
||||
|
||||
REQUIREMENTS = ['fritzconnection==0.4.6']
|
||||
|
||||
# Return cached results if last scan was less then this time ago
|
||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=5)
|
||||
|
||||
@@ -55,16 +57,8 @@ class FritzBoxScanner(object):
|
||||
self.password = ''
|
||||
self.success_init = True
|
||||
|
||||
# Try to import the fritzconnection library
|
||||
try:
|
||||
# noinspection PyPackageRequirements,PyUnresolvedReferences
|
||||
import fritzconnection as fc
|
||||
except ImportError:
|
||||
_LOGGER.exception("""Failed to import Python library
|
||||
fritzconnection. Please run
|
||||
<home-assistant>/setup to install it.""")
|
||||
self.success_init = False
|
||||
return
|
||||
# pylint: disable=import-error
|
||||
import fritzconnection as fc
|
||||
|
||||
# Check for user specific configuration
|
||||
if CONF_HOST in config.keys():
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
"""
|
||||
homeassistant.components.device_tracker.geofancy
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Geofancy platform for the device tracker.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/device_tracker.geofancy/
|
||||
"""
|
||||
from homeassistant.const import (
|
||||
HTTP_UNPROCESSABLE_ENTITY, HTTP_INTERNAL_SERVER_ERROR)
|
||||
|
||||
DEPENDENCIES = ['http']
|
||||
|
||||
_SEE = 0
|
||||
|
||||
URL_API_GEOFANCY_ENDPOINT = "/api/geofancy"
|
||||
|
||||
|
||||
def setup_scanner(hass, config, see):
|
||||
""" Set up an endpoint for the Geofancy app. """
|
||||
|
||||
# Use a global variable to keep setup_scanner compact when using a callback
|
||||
global _SEE
|
||||
_SEE = see
|
||||
|
||||
# POST would be semantically better, but that currently does not work
|
||||
# since Geofancy sends the data as key1=value1&key2=value2
|
||||
# in the request body, while Home Assistant expects json there.
|
||||
|
||||
hass.http.register_path(
|
||||
'GET', URL_API_GEOFANCY_ENDPOINT, _handle_get_api_geofancy)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def _handle_get_api_geofancy(handler, path_match, data):
|
||||
""" Geofancy message received. """
|
||||
|
||||
if not isinstance(data, dict):
|
||||
handler.write_json_message(
|
||||
"Error while parsing Geofancy message.",
|
||||
HTTP_INTERNAL_SERVER_ERROR)
|
||||
return
|
||||
if 'latitude' not in data or 'longitude' not in data:
|
||||
handler.write_json_message(
|
||||
"Location not specified.",
|
||||
HTTP_UNPROCESSABLE_ENTITY)
|
||||
return
|
||||
if 'device' not in data or 'id' not in data:
|
||||
handler.write_json_message(
|
||||
"Device id or location id not specified.",
|
||||
HTTP_UNPROCESSABLE_ENTITY)
|
||||
return
|
||||
|
||||
try:
|
||||
gps_coords = (float(data['latitude']), float(data['longitude']))
|
||||
except ValueError:
|
||||
# If invalid latitude / longitude format
|
||||
handler.write_json_message(
|
||||
"Invalid latitude / longitude format.",
|
||||
HTTP_UNPROCESSABLE_ENTITY)
|
||||
return
|
||||
|
||||
# entity id's in Home Assistant must be alphanumerical
|
||||
device_uuid = data['device']
|
||||
device_entity_id = device_uuid.replace('-', '')
|
||||
|
||||
_SEE(dev_id=device_entity_id, gps=gps_coords, location_name=data['id'])
|
||||
|
||||
handler.write_json_message("Geofancy message processed")
|
||||
@@ -0,0 +1,104 @@
|
||||
"""
|
||||
homeassistant.components.device_tracker.locative
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Locative platform for the device tracker.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/device_tracker.locative/
|
||||
"""
|
||||
import logging
|
||||
from functools import partial
|
||||
|
||||
from homeassistant.const import (
|
||||
HTTP_UNPROCESSABLE_ENTITY, STATE_NOT_HOME)
|
||||
from homeassistant.components.device_tracker import DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEPENDENCIES = ['http']
|
||||
|
||||
URL_API_LOCATIVE_ENDPOINT = "/api/locative"
|
||||
|
||||
|
||||
def setup_scanner(hass, config, see):
|
||||
""" Set up an endpoint for the Locative app. """
|
||||
|
||||
# POST would be semantically better, but that currently does not work
|
||||
# since Locative sends the data as key1=value1&key2=value2
|
||||
# in the request body, while Home Assistant expects json there.
|
||||
|
||||
hass.http.register_path(
|
||||
'GET', URL_API_LOCATIVE_ENDPOINT,
|
||||
partial(_handle_get_api_locative, hass, see))
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def _handle_get_api_locative(hass, see, handler, path_match, data):
|
||||
""" Locative message received. """
|
||||
|
||||
if not _check_data(handler, data):
|
||||
return
|
||||
|
||||
device = data['device'].replace('-', '')
|
||||
location_name = data['id'].lower()
|
||||
direction = data['trigger']
|
||||
|
||||
if direction == 'enter':
|
||||
see(dev_id=device, location_name=location_name)
|
||||
handler.write_text("Setting location to {}".format(location_name))
|
||||
|
||||
elif direction == 'exit':
|
||||
current_state = hass.states.get("{}.{}".format(DOMAIN, device))
|
||||
|
||||
if current_state is None or current_state.state == location_name:
|
||||
see(dev_id=device, location_name=STATE_NOT_HOME)
|
||||
handler.write_text("Setting location to not home")
|
||||
else:
|
||||
# Ignore the message if it is telling us to exit a zone that we
|
||||
# aren't currently in. This occurs when a zone is entered before
|
||||
# the previous zone was exited. The enter message will be sent
|
||||
# first, then the exit message will be sent second.
|
||||
handler.write_text(
|
||||
'Ignoring exit from {} (already in {})'.format(
|
||||
location_name, current_state))
|
||||
|
||||
elif direction == 'test':
|
||||
# In the app, a test message can be sent. Just return something to
|
||||
# the user to let them know that it works.
|
||||
handler.write_text("Received test message.")
|
||||
|
||||
else:
|
||||
handler.write_text(
|
||||
"Received unidentified message: {}".format(direction),
|
||||
HTTP_UNPROCESSABLE_ENTITY)
|
||||
_LOGGER.error("Received unidentified message from Locative: %s",
|
||||
direction)
|
||||
|
||||
|
||||
def _check_data(handler, data):
|
||||
if 'latitude' not in data or 'longitude' not in data:
|
||||
handler.write_text("Latitude and longitude not specified.",
|
||||
HTTP_UNPROCESSABLE_ENTITY)
|
||||
_LOGGER.error("Latitude and longitude not specified.")
|
||||
return False
|
||||
|
||||
if 'device' not in data:
|
||||
handler.write_text("Device id not specified.",
|
||||
HTTP_UNPROCESSABLE_ENTITY)
|
||||
_LOGGER.error("Device id not specified.")
|
||||
return False
|
||||
|
||||
if 'id' not in data:
|
||||
handler.write_text("Location id not specified.",
|
||||
HTTP_UNPROCESSABLE_ENTITY)
|
||||
_LOGGER.error("Location id not specified.")
|
||||
return False
|
||||
|
||||
if 'trigger' not in data:
|
||||
handler.write_text("Trigger is not specified.",
|
||||
HTTP_UNPROCESSABLE_ENTITY)
|
||||
_LOGGER.error("Trigger is not specified.")
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -19,7 +19,7 @@ from homeassistant.components.device_tracker import DOMAIN
|
||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=5)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
REQUIREMENTS = ['pynetgear==0.3']
|
||||
REQUIREMENTS = ['pynetgear==0.3.2']
|
||||
|
||||
|
||||
def get_scanner(hass, config):
|
||||
|
||||
@@ -8,16 +8,29 @@ https://home-assistant.io/components/device_tracker.owntracks/
|
||||
"""
|
||||
import json
|
||||
import logging
|
||||
import threading
|
||||
from collections import defaultdict
|
||||
|
||||
import homeassistant.components.mqtt as mqtt
|
||||
from homeassistant.const import STATE_HOME
|
||||
|
||||
DEPENDENCIES = ['mqtt']
|
||||
|
||||
REGIONS_ENTERED = defaultdict(list)
|
||||
MOBILE_BEACONS_ACTIVE = defaultdict(list)
|
||||
|
||||
BEACON_DEV_ID = 'beacon'
|
||||
|
||||
LOCATION_TOPIC = 'owntracks/+/+'
|
||||
EVENT_TOPIC = 'owntracks/+/+/event'
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
LOCK = threading.Lock()
|
||||
|
||||
|
||||
def setup_scanner(hass, config, see):
|
||||
""" Set up a OwnTracksks tracker. """
|
||||
""" Set up an OwnTracks tracker. """
|
||||
|
||||
def owntracks_location_update(topic, payload, qos):
|
||||
""" MQTT message received. """
|
||||
@@ -28,26 +41,141 @@ def setup_scanner(hass, config, see):
|
||||
data = json.loads(payload)
|
||||
except ValueError:
|
||||
# If invalid JSON
|
||||
logging.getLogger(__name__).error(
|
||||
_LOGGER.error(
|
||||
'Unable to parse payload as JSON: %s', payload)
|
||||
return
|
||||
|
||||
if not isinstance(data, dict) or data.get('_type') != 'location':
|
||||
return
|
||||
|
||||
parts = topic.split('/')
|
||||
kwargs = {
|
||||
'dev_id': '{}_{}'.format(parts[1], parts[2]),
|
||||
'host_name': parts[1],
|
||||
'gps': (data['lat'], data['lon']),
|
||||
}
|
||||
if 'acc' in data:
|
||||
kwargs['gps_accuracy'] = data['acc']
|
||||
if 'batt' in data:
|
||||
kwargs['battery'] = data['batt']
|
||||
dev_id, kwargs = _parse_see_args(topic, data)
|
||||
|
||||
see(**kwargs)
|
||||
# Block updates if we're in a region
|
||||
with LOCK:
|
||||
if REGIONS_ENTERED[dev_id]:
|
||||
_LOGGER.debug(
|
||||
"location update ignored - inside region %s",
|
||||
REGIONS_ENTERED[-1])
|
||||
return
|
||||
|
||||
see(**kwargs)
|
||||
see_beacons(dev_id, kwargs)
|
||||
|
||||
def owntracks_event_update(topic, payload, qos):
|
||||
# pylint: disable=too-many-branches
|
||||
""" MQTT event (geofences) received. """
|
||||
|
||||
# Docs on available data:
|
||||
# http://owntracks.org/booklet/tech/json/#_typetransition
|
||||
try:
|
||||
data = json.loads(payload)
|
||||
except ValueError:
|
||||
# If invalid JSON
|
||||
_LOGGER.error(
|
||||
'Unable to parse payload as JSON: %s', payload)
|
||||
return
|
||||
|
||||
if not isinstance(data, dict) or data.get('_type') != 'transition':
|
||||
return
|
||||
|
||||
# OwnTracks uses - at the start of a beacon zone
|
||||
# to switch on 'hold mode' - ignore this
|
||||
location = data['desc'].lstrip("-")
|
||||
if location.lower() == 'home':
|
||||
location = STATE_HOME
|
||||
|
||||
dev_id, kwargs = _parse_see_args(topic, data)
|
||||
|
||||
if data['event'] == 'enter':
|
||||
zone = hass.states.get("zone.{}".format(location))
|
||||
with LOCK:
|
||||
if zone is None:
|
||||
if data['t'] == 'b':
|
||||
# Not a HA zone, and a beacon so assume mobile
|
||||
MOBILE_BEACONS_ACTIVE[dev_id].append(location)
|
||||
else:
|
||||
# Normal region
|
||||
kwargs['location_name'] = location
|
||||
|
||||
regions = REGIONS_ENTERED[dev_id]
|
||||
if location not in regions:
|
||||
regions.append(location)
|
||||
_LOGGER.info("Enter region %s", location)
|
||||
_set_gps_from_zone(kwargs, zone)
|
||||
|
||||
see(**kwargs)
|
||||
see_beacons(dev_id, kwargs)
|
||||
|
||||
elif data['event'] == 'leave':
|
||||
regions = REGIONS_ENTERED[dev_id]
|
||||
if location in regions:
|
||||
regions.remove(location)
|
||||
new_region = regions[-1] if regions else None
|
||||
|
||||
if new_region:
|
||||
# Exit to previous region
|
||||
zone = hass.states.get("zone.{}".format(new_region))
|
||||
kwargs['location_name'] = new_region
|
||||
_set_gps_from_zone(kwargs, zone)
|
||||
_LOGGER.info("Exit from to %s", new_region)
|
||||
|
||||
else:
|
||||
_LOGGER.info("Exit to GPS")
|
||||
|
||||
see(**kwargs)
|
||||
see_beacons(dev_id, kwargs)
|
||||
|
||||
beacons = MOBILE_BEACONS_ACTIVE[dev_id]
|
||||
if location in beacons:
|
||||
beacons.remove(location)
|
||||
|
||||
else:
|
||||
_LOGGER.error(
|
||||
'Misformatted mqtt msgs, _type=transition, event=%s',
|
||||
data['event'])
|
||||
return
|
||||
|
||||
def see_beacons(dev_id, kwargs_param):
|
||||
""" Set active beacons to the current location """
|
||||
|
||||
kwargs = kwargs_param.copy()
|
||||
for beacon in MOBILE_BEACONS_ACTIVE[dev_id]:
|
||||
kwargs['dev_id'] = "{}_{}".format(BEACON_DEV_ID, beacon)
|
||||
kwargs['host_name'] = beacon
|
||||
see(**kwargs)
|
||||
|
||||
mqtt.subscribe(hass, LOCATION_TOPIC, owntracks_location_update, 1)
|
||||
|
||||
mqtt.subscribe(hass, EVENT_TOPIC, owntracks_event_update, 1)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def _parse_see_args(topic, data):
|
||||
""" Parse the OwnTracks location parameters,
|
||||
into the format see expects. """
|
||||
|
||||
parts = topic.split('/')
|
||||
dev_id = '{}_{}'.format(parts[1], parts[2])
|
||||
host_name = parts[1]
|
||||
kwargs = {
|
||||
'dev_id': dev_id,
|
||||
'host_name': host_name,
|
||||
'gps': (data['lat'], data['lon'])
|
||||
}
|
||||
if 'acc' in data:
|
||||
kwargs['gps_accuracy'] = data['acc']
|
||||
if 'batt' in data:
|
||||
kwargs['battery'] = data['batt']
|
||||
return dev_id, kwargs
|
||||
|
||||
|
||||
def _set_gps_from_zone(kwargs, zone):
|
||||
""" Set the see parameters from the zone parameters """
|
||||
|
||||
if zone is not None:
|
||||
kwargs['gps'] = (
|
||||
zone.attributes['latitude'],
|
||||
zone.attributes['longitude'])
|
||||
kwargs['gps_accuracy'] = zone.attributes['radius']
|
||||
return kwargs
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# Describes the format for available device tracker services
|
||||
|
||||
see:
|
||||
description: Control tracked device
|
||||
|
||||
fields:
|
||||
mac:
|
||||
description: MAC address of device
|
||||
example: 'FF:FF:FF:FF:FF:FF'
|
||||
|
||||
dev_id:
|
||||
description: Id of device (find id in known_devices.yaml)
|
||||
example: 'phonedave'
|
||||
|
||||
host_name:
|
||||
description: Hostname of device
|
||||
example: 'Dave'
|
||||
|
||||
location_name:
|
||||
description: Name of location where device is located (not_home is away)
|
||||
example: 'home'
|
||||
|
||||
gps:
|
||||
description: GPS coordinates where device is located (latitude, longitude)
|
||||
example: '[51.509802, -0.086692]'
|
||||
|
||||
gps_accuracy:
|
||||
description: Accuracy of GPS coordinates
|
||||
example: '80'
|
||||
|
||||
battery:
|
||||
description: Battery level of device
|
||||
example: '100'
|
||||
|
||||
@@ -105,8 +105,7 @@ class SnmpScanner(object):
|
||||
return
|
||||
if errstatus:
|
||||
_LOGGER.error('SNMP error: %s at %s', errstatus.prettyPrint(),
|
||||
errindex and restable[-1][int(errindex)-1]
|
||||
or '?')
|
||||
errindex and restable[-1][int(errindex)-1] or '?')
|
||||
return
|
||||
|
||||
for resrow in restable:
|
||||
|
||||
@@ -242,8 +242,8 @@ class Tplink3DeviceScanner(TplinkDeviceScanner):
|
||||
|
||||
_LOGGER.info("Loading wireless clients...")
|
||||
|
||||
url = 'http://{}/cgi-bin/luci/;stok={}/admin/wireless?form=statistics' \
|
||||
.format(self.host, self.stok)
|
||||
url = ('http://{}/cgi-bin/luci/;stok={}/admin/wireless?'
|
||||
'form=statistics').format(self.host, self.stok)
|
||||
referer = 'http://{}/webpages/index.html'.format(self.host)
|
||||
|
||||
response = requests.post(url,
|
||||
|
||||
@@ -11,6 +11,8 @@ import logging
|
||||
import re
|
||||
import threading
|
||||
|
||||
import requests
|
||||
|
||||
from homeassistant.helpers import validate_config
|
||||
from homeassistant.util import sanitize_filename
|
||||
|
||||
@@ -30,14 +32,6 @@ def setup(hass, config):
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
import requests
|
||||
except ImportError:
|
||||
logger.exception(("Failed to import requests. "
|
||||
"Did you maybe not execute 'pip install requests'?"))
|
||||
|
||||
return False
|
||||
|
||||
if not validate_config(config, {DOMAIN: [CONF_DOWNLOAD_DIR]}, logger):
|
||||
return False
|
||||
|
||||
|
||||
@@ -21,7 +21,9 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
FRONTEND_URLS = [
|
||||
URL_ROOT, '/logbook', '/history', '/map', '/devService', '/devState',
|
||||
'/devEvent', '/devInfo', '/devTemplate', '/states']
|
||||
'/devEvent', '/devInfo', '/devTemplate',
|
||||
re.compile(r'/states(/([a-zA-Z\._\-0-9/]+)|)'),
|
||||
]
|
||||
|
||||
_FINGERPRINT = re.compile(r'^(\w+)-[a-z0-9]{32}\.(\w+)$', re.IGNORECASE)
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
""" DO NOT MODIFY. Auto-generated by update_mdi script """
|
||||
VERSION = "7d76081c37634d36af21f5cc1ca79408"
|
||||
VERSION = "a2605736c8d959d50c4bcbba1e6a6aa5"
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
""" DO NOT MODIFY. Auto-generated by build_frontend script """
|
||||
VERSION = "be08c5a3ce12040bbdba2db83cb1a568"
|
||||
VERSION = "1e89871aaae43c91b2508f52bc161b69"
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -7,20 +7,24 @@ For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/group/
|
||||
"""
|
||||
import homeassistant.core as ha
|
||||
from homeassistant.helpers import generate_entity_id
|
||||
from homeassistant.helpers.event import track_state_change
|
||||
from homeassistant.helpers.entity import Entity
|
||||
import homeassistant.util as util
|
||||
from homeassistant.helpers.entity import (
|
||||
Entity, split_entity_id, generate_entity_id)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, STATE_ON, STATE_OFF,
|
||||
STATE_HOME, STATE_NOT_HOME, STATE_OPEN, STATE_CLOSED,
|
||||
STATE_UNKNOWN)
|
||||
STATE_UNKNOWN, CONF_NAME, CONF_ICON)
|
||||
|
||||
DOMAIN = "group"
|
||||
DOMAIN = 'group'
|
||||
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
ENTITY_ID_FORMAT = DOMAIN + '.{}'
|
||||
|
||||
ATTR_AUTO = "auto"
|
||||
CONF_ENTITIES = 'entities'
|
||||
CONF_VIEW = 'view'
|
||||
|
||||
ATTR_AUTO = 'auto'
|
||||
ATTR_ORDER = 'order'
|
||||
ATTR_VIEW = 'view'
|
||||
|
||||
# List of ON/OFF state tuples for groupable states
|
||||
_GROUP_TYPES = [(STATE_ON, STATE_OFF), (STATE_HOME, STATE_NOT_HOME),
|
||||
@@ -62,7 +66,7 @@ def expand_entity_ids(hass, entity_ids):
|
||||
|
||||
try:
|
||||
# If entity_id points at a group, expand it
|
||||
domain, _ = util.split_entity_id(entity_id)
|
||||
domain, _ = split_entity_id(entity_id)
|
||||
|
||||
if domain == DOMAIN:
|
||||
found_ids.extend(
|
||||
@@ -75,7 +79,7 @@ def expand_entity_ids(hass, entity_ids):
|
||||
found_ids.append(entity_id)
|
||||
|
||||
except AttributeError:
|
||||
# Raised by util.split_entity_id if entity_id is not a string
|
||||
# Raised by split_entity_id if entity_id is not a string
|
||||
pass
|
||||
|
||||
return found_ids
|
||||
@@ -104,10 +108,20 @@ def get_entity_ids(hass, entity_id, domain_filter=None):
|
||||
|
||||
def setup(hass, config):
|
||||
""" Sets up all groups found definded in the configuration. """
|
||||
for name, entity_ids in config.get(DOMAIN, {}).items():
|
||||
for object_id, conf in config.get(DOMAIN, {}).items():
|
||||
if not isinstance(conf, dict):
|
||||
conf = {CONF_ENTITIES: conf}
|
||||
|
||||
name = conf.get(CONF_NAME, object_id)
|
||||
entity_ids = conf.get(CONF_ENTITIES)
|
||||
icon = conf.get(CONF_ICON)
|
||||
view = conf.get(CONF_VIEW)
|
||||
|
||||
if isinstance(entity_ids, str):
|
||||
entity_ids = [ent.strip() for ent in entity_ids.split(",")]
|
||||
setup_group(hass, name, entity_ids)
|
||||
|
||||
Group(hass, name, entity_ids, icon=icon, view=view,
|
||||
object_id=object_id)
|
||||
|
||||
return True
|
||||
|
||||
@@ -115,14 +129,19 @@ def setup(hass, config):
|
||||
class Group(Entity):
|
||||
""" Tracks a group of entity ids. """
|
||||
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
# pylint: disable=too-many-instance-attributes, too-many-arguments
|
||||
|
||||
def __init__(self, hass, name, entity_ids=None, user_defined=True):
|
||||
def __init__(self, hass, name, entity_ids=None, user_defined=True,
|
||||
icon=None, view=False, object_id=None):
|
||||
self.hass = hass
|
||||
self._name = name
|
||||
self._state = STATE_UNKNOWN
|
||||
self.user_defined = user_defined
|
||||
self.entity_id = generate_entity_id(ENTITY_ID_FORMAT, name, hass=hass)
|
||||
self._order = len(hass.states.entity_ids(DOMAIN))
|
||||
self._user_defined = user_defined
|
||||
self._icon = icon
|
||||
self._view = view
|
||||
self.entity_id = generate_entity_id(
|
||||
ENTITY_ID_FORMAT, object_id or name, hass=hass)
|
||||
self.tracking = []
|
||||
self.group_on = None
|
||||
self.group_off = None
|
||||
@@ -144,12 +163,25 @@ class Group(Entity):
|
||||
def state(self):
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
return self._icon
|
||||
|
||||
@property
|
||||
def hidden(self):
|
||||
return not self._user_defined or self._view
|
||||
|
||||
@property
|
||||
def state_attributes(self):
|
||||
return {
|
||||
data = {
|
||||
ATTR_ENTITY_ID: self.tracking,
|
||||
ATTR_AUTO: not self.user_defined,
|
||||
ATTR_ORDER: self._order,
|
||||
}
|
||||
if not self._user_defined:
|
||||
data[ATTR_AUTO] = True
|
||||
if self._view:
|
||||
data[ATTR_VIEW] = True
|
||||
return data
|
||||
|
||||
def update_tracked_entity_ids(self, entity_ids):
|
||||
""" Update the tracked entity IDs. """
|
||||
@@ -220,10 +252,3 @@ class Group(Entity):
|
||||
for ent_id in self.tracking
|
||||
if tr_state.entity_id != ent_id):
|
||||
self._state = group_off
|
||||
|
||||
|
||||
def setup_group(hass, name, entity_ids, user_defined=True):
|
||||
""" Sets up a group state that is the combined state of
|
||||
several states. Supports ON/OFF and DEVICE_HOME/DEVICE_NOT_HOME. """
|
||||
|
||||
return Group(hass, name, entity_ids, user_defined)
|
||||
|
||||
@@ -21,7 +21,7 @@ from urllib.parse import urlparse, parse_qs
|
||||
|
||||
import homeassistant.core as ha
|
||||
from homeassistant.const import (
|
||||
SERVER_PORT, CONTENT_TYPE_JSON,
|
||||
SERVER_PORT, CONTENT_TYPE_JSON, CONTENT_TYPE_TEXT_PLAIN,
|
||||
HTTP_HEADER_HA_AUTH, HTTP_HEADER_CONTENT_TYPE, HTTP_HEADER_ACCEPT_ENCODING,
|
||||
HTTP_HEADER_CONTENT_ENCODING, HTTP_HEADER_VARY, HTTP_HEADER_CONTENT_LENGTH,
|
||||
HTTP_HEADER_CACHE_CONTROL, HTTP_HEADER_EXPIRES, HTTP_OK, HTTP_UNAUTHORIZED,
|
||||
@@ -112,10 +112,10 @@ class HomeAssistantHTTPServer(ThreadingMixIn, HTTPServer):
|
||||
_LOGGER.info("running http in development mode")
|
||||
|
||||
if ssl_certificate is not None:
|
||||
wrap_kwargs = {'certfile': ssl_certificate}
|
||||
if ssl_key is not None:
|
||||
wrap_kwargs['keyfile'] = ssl_key
|
||||
self.socket = ssl.wrap_socket(self.socket, **wrap_kwargs)
|
||||
context = ssl.create_default_context(
|
||||
purpose=ssl.Purpose.CLIENT_AUTH)
|
||||
context.load_cert_chain(ssl_certificate, keyfile=ssl_key)
|
||||
self.socket = context.wrap_socket(self.socket, server_side=True)
|
||||
|
||||
def start(self):
|
||||
""" Starts the HTTP server. """
|
||||
@@ -198,12 +198,12 @@ class RequestHandler(SimpleHTTPRequestHandler):
|
||||
"Error parsing JSON", HTTP_UNPROCESSABLE_ENTITY)
|
||||
return
|
||||
|
||||
self.authenticated = (self.server.api_password is None
|
||||
or self.headers.get(HTTP_HEADER_HA_AUTH) ==
|
||||
self.server.api_password
|
||||
or data.get(DATA_API_PASSWORD) ==
|
||||
self.server.api_password
|
||||
or self.verify_session())
|
||||
self.authenticated = (self.server.api_password is None or
|
||||
self.headers.get(HTTP_HEADER_HA_AUTH) ==
|
||||
self.server.api_password or
|
||||
data.get(DATA_API_PASSWORD) ==
|
||||
self.server.api_password or
|
||||
self.verify_session())
|
||||
|
||||
if '_METHOD' in data:
|
||||
method = data.pop('_METHOD')
|
||||
@@ -293,6 +293,17 @@ class RequestHandler(SimpleHTTPRequestHandler):
|
||||
json.dumps(data, indent=4, sort_keys=True,
|
||||
cls=rem.JSONEncoder).encode("UTF-8"))
|
||||
|
||||
def write_text(self, message, status_code=HTTP_OK):
|
||||
""" Helper method to return a text message to the caller. """
|
||||
self.send_response(status_code)
|
||||
self.send_header(HTTP_HEADER_CONTENT_TYPE, CONTENT_TYPE_TEXT_PLAIN)
|
||||
|
||||
self.set_session_cookie_header()
|
||||
|
||||
self.end_headers()
|
||||
|
||||
self.wfile.write(message.encode("UTF-8"))
|
||||
|
||||
def write_file(self, path, cache_headers=True):
|
||||
""" Returns a file to the user. """
|
||||
try:
|
||||
|
||||
@@ -7,7 +7,6 @@ For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/influxdb/
|
||||
"""
|
||||
import logging
|
||||
|
||||
import homeassistant.util as util
|
||||
from homeassistant.helpers import validate_config
|
||||
from homeassistant.const import (EVENT_STATE_CHANGED, STATE_ON, STATE_OFF,
|
||||
@@ -24,7 +23,7 @@ DEFAULT_HOST = 'localhost'
|
||||
DEFAULT_PORT = 8086
|
||||
DEFAULT_DATABASE = 'home_assistant'
|
||||
|
||||
REQUIREMENTS = ['influxdb==2.10.0']
|
||||
REQUIREMENTS = ['influxdb==2.11.0']
|
||||
|
||||
CONF_HOST = 'host'
|
||||
CONF_PORT = 'port'
|
||||
@@ -52,14 +51,11 @@ def setup(hass, config):
|
||||
try:
|
||||
influx = InfluxDBClient(host=host, port=port, username=username,
|
||||
password=password, database=database)
|
||||
databases = [i['name'] for i in influx.get_list_database()]
|
||||
except exceptions.InfluxDBClientError:
|
||||
_LOGGER.error("Database host is not accessible. "
|
||||
"Please check your entries in the configuration file.")
|
||||
return False
|
||||
|
||||
if database not in databases:
|
||||
_LOGGER.error("Database %s doesn't exist", database)
|
||||
influx.query("select * from /.*/ LIMIT 1;")
|
||||
except exceptions.InfluxDBClientError as exc:
|
||||
_LOGGER.error("Database host is not accessible due to '%s', please "
|
||||
"check your entries in the configuration file and that"
|
||||
" the database exists and is READ/WRITE.", exc)
|
||||
return False
|
||||
|
||||
def influx_event_listener(event):
|
||||
@@ -77,6 +73,12 @@ def setup(hass, config):
|
||||
_state = 0
|
||||
else:
|
||||
_state = state.state
|
||||
if _state == '':
|
||||
return
|
||||
try:
|
||||
_state = float(_state)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
measurement = state.attributes.get('unit_of_measurement', state.domain)
|
||||
|
||||
@@ -97,7 +99,7 @@ def setup(hass, config):
|
||||
try:
|
||||
influx.write_points(json_body)
|
||||
except exceptions.InfluxDBClientError:
|
||||
_LOGGER.exception('Error saving event to InfluxDB')
|
||||
_LOGGER.exception('Error saving event "%s" to InfluxDB', json_body)
|
||||
|
||||
hass.bus.listen(EVENT_STATE_CHANGED, influx_event_listener)
|
||||
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
"""
|
||||
homeassistant.components.input_boolean
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Component to keep track of user controlled booleans for within automation.
|
||||
|
||||
For more details about this component, please refer to the documentation
|
||||
at https://home-assistant.io/components/input_boolean/
|
||||
"""
|
||||
import logging
|
||||
|
||||
from homeassistant.const import (
|
||||
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, ATTR_ENTITY_ID)
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.entity import ToggleEntity
|
||||
from homeassistant.util import slugify
|
||||
|
||||
DOMAIN = 'input_boolean'
|
||||
|
||||
ENTITY_ID_FORMAT = DOMAIN + '.{}'
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_NAME = "name"
|
||||
CONF_INITIAL = "initial"
|
||||
CONF_ICON = "icon"
|
||||
|
||||
|
||||
def is_on(hass, entity_id):
|
||||
"""Test if input_boolean is True."""
|
||||
return hass.states.is_state(entity_id, STATE_ON)
|
||||
|
||||
|
||||
def turn_on(hass, entity_id):
|
||||
"""Set input_boolean to True."""
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: entity_id})
|
||||
|
||||
|
||||
def turn_off(hass, entity_id):
|
||||
"""Set input_boolean to False."""
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: entity_id})
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
"""Set up input booleans."""
|
||||
if not isinstance(config.get(DOMAIN), dict):
|
||||
_LOGGER.error('Expected %s config to be a dictionary', DOMAIN)
|
||||
return False
|
||||
|
||||
component = EntityComponent(_LOGGER, DOMAIN, hass)
|
||||
|
||||
entities = []
|
||||
|
||||
for object_id, cfg in config[DOMAIN].items():
|
||||
if object_id != slugify(object_id):
|
||||
_LOGGER.warning("Found invalid key for boolean input: %s. "
|
||||
"Use %s instead", object_id, slugify(object_id))
|
||||
continue
|
||||
if not cfg:
|
||||
cfg = {}
|
||||
|
||||
name = cfg.get(CONF_NAME)
|
||||
state = cfg.get(CONF_INITIAL, False)
|
||||
icon = cfg.get(CONF_ICON)
|
||||
|
||||
entities.append(InputBoolean(object_id, name, state, icon))
|
||||
|
||||
if not entities:
|
||||
return False
|
||||
|
||||
def toggle_service(service):
|
||||
"""Handle a calls to the input boolean services."""
|
||||
target_inputs = component.extract_from_service(service)
|
||||
|
||||
for input_b in target_inputs:
|
||||
if service.service == SERVICE_TURN_ON:
|
||||
input_b.turn_on()
|
||||
else:
|
||||
input_b.turn_off()
|
||||
|
||||
hass.services.register(DOMAIN, SERVICE_TURN_OFF, toggle_service)
|
||||
hass.services.register(DOMAIN, SERVICE_TURN_ON, toggle_service)
|
||||
|
||||
component.add_entities(entities)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
class InputBoolean(ToggleEntity):
|
||||
"""Represent a boolean input within Home Assistant."""
|
||||
|
||||
def __init__(self, object_id, name, state, icon):
|
||||
"""Initialize a boolean input."""
|
||||
self.entity_id = ENTITY_ID_FORMAT.format(object_id)
|
||||
self._name = name
|
||||
self._state = state
|
||||
self._icon = icon
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""If entitiy should be polled."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Name of the boolean input."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Icon to be used for this entity."""
|
||||
return self._icon
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""True if entity is on."""
|
||||
return self._state
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn the entity on."""
|
||||
self._state = True
|
||||
self.update_ha_state()
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
"""Turn the entity off."""
|
||||
self._state = False
|
||||
self.update_ha_state()
|
||||
@@ -0,0 +1,93 @@
|
||||
"""
|
||||
homeassistant.components.insteon
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Support for Insteon Hub.
|
||||
|
||||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/insteon/
|
||||
"""
|
||||
import logging
|
||||
import homeassistant.bootstrap as bootstrap
|
||||
from homeassistant.helpers import validate_config
|
||||
from homeassistant.loader import get_component
|
||||
from homeassistant.helpers.entity import ToggleEntity
|
||||
from homeassistant.const import (
|
||||
CONF_USERNAME, CONF_PASSWORD, CONF_API_KEY, ATTR_DISCOVERED,
|
||||
ATTR_SERVICE, EVENT_PLATFORM_DISCOVERED)
|
||||
|
||||
DOMAIN = "insteon_hub"
|
||||
REQUIREMENTS = ['insteon_hub==0.4.5']
|
||||
INSTEON = None
|
||||
DISCOVER_LIGHTS = "insteon_hub.lights"
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
"""
|
||||
Setup Insteon Hub component.
|
||||
This will automatically import associated lights.
|
||||
"""
|
||||
if not validate_config(
|
||||
config,
|
||||
{DOMAIN: [CONF_USERNAME, CONF_PASSWORD, CONF_API_KEY]},
|
||||
_LOGGER):
|
||||
return False
|
||||
|
||||
import insteon
|
||||
|
||||
username = config[DOMAIN][CONF_USERNAME]
|
||||
password = config[DOMAIN][CONF_PASSWORD]
|
||||
api_key = config[DOMAIN][CONF_API_KEY]
|
||||
|
||||
global INSTEON
|
||||
INSTEON = insteon.Insteon(username, password, api_key)
|
||||
|
||||
if INSTEON is None:
|
||||
_LOGGER.error("Could not connect to Insteon service.")
|
||||
return
|
||||
|
||||
comp_name = 'light'
|
||||
discovery = DISCOVER_LIGHTS
|
||||
component = get_component(comp_name)
|
||||
bootstrap.setup_component(hass, component.DOMAIN, config)
|
||||
hass.bus.fire(
|
||||
EVENT_PLATFORM_DISCOVERED,
|
||||
{ATTR_SERVICE: discovery, ATTR_DISCOVERED: {}})
|
||||
return True
|
||||
|
||||
|
||||
class InsteonToggleDevice(ToggleEntity):
|
||||
""" Abstract Class for an Insteon node. """
|
||||
|
||||
def __init__(self, node):
|
||||
self.node = node
|
||||
self._value = 0
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" Returns the name of the node. """
|
||||
return self.node.DeviceName
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
""" Returns the id of this insteon node. """
|
||||
return self.node.DeviceID
|
||||
|
||||
def update(self):
|
||||
""" Update state of the sensor. """
|
||||
resp = self.node.send_command('get_status', wait=True)
|
||||
try:
|
||||
self._value = resp['response']['level']
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
""" Returns boolean response if the node is on. """
|
||||
return self._value != 0
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
self.node.send_command('on')
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
self.node.send_command('off')
|
||||
@@ -37,11 +37,7 @@ def setup(hass, config):
|
||||
Setup ISY994 component.
|
||||
This will automatically import associated lights, switches, and sensors.
|
||||
"""
|
||||
try:
|
||||
import PyISY
|
||||
except ImportError:
|
||||
_LOGGER.error("Error while importing dependency PyISY.")
|
||||
return False
|
||||
import PyISY
|
||||
|
||||
# pylint: disable=global-statement
|
||||
# check for required values in configuration file
|
||||
|
||||
@@ -6,8 +6,6 @@ Provides functionality to emulate keyboard presses on host machine.
|
||||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/keyboard/
|
||||
"""
|
||||
import logging
|
||||
|
||||
from homeassistant.const import (
|
||||
SERVICE_VOLUME_UP, SERVICE_VOLUME_DOWN, SERVICE_VOLUME_MUTE,
|
||||
SERVICE_MEDIA_NEXT_TRACK, SERVICE_MEDIA_PREVIOUS_TRACK,
|
||||
@@ -50,13 +48,7 @@ def media_prev_track(hass):
|
||||
|
||||
def setup(hass, config):
|
||||
""" Listen for keyboard events. """
|
||||
try:
|
||||
import pykeyboard
|
||||
except ImportError:
|
||||
logging.getLogger(__name__).exception(
|
||||
"Error while importing dependency PyUserInput.")
|
||||
|
||||
return False
|
||||
import pykeyboard
|
||||
|
||||
keyboard = pykeyboard.PyKeyboard()
|
||||
keyboard.special_key_assignment()
|
||||
|
||||
@@ -10,10 +10,12 @@ import logging
|
||||
import os
|
||||
import csv
|
||||
|
||||
from homeassistant.components import group, discovery, wink, isy994, zwave
|
||||
from homeassistant.components import (
|
||||
group, discovery, wink, isy994, zwave, insteon_hub)
|
||||
from homeassistant.config import load_yaml_config_file
|
||||
from homeassistant.const import (
|
||||
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, ATTR_ENTITY_ID)
|
||||
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE,
|
||||
ATTR_ENTITY_ID)
|
||||
from homeassistant.helpers.entity import ToggleEntity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
import homeassistant.util as util
|
||||
@@ -50,6 +52,7 @@ FLASH_LONG = "long"
|
||||
# Apply an effect to the light, can be EFFECT_COLORLOOP
|
||||
ATTR_EFFECT = "effect"
|
||||
EFFECT_COLORLOOP = "colorloop"
|
||||
EFFECT_RANDOM = "random"
|
||||
EFFECT_WHITE = "white"
|
||||
|
||||
LIGHT_PROFILES_FILE = "light_profiles.csv"
|
||||
@@ -57,6 +60,7 @@ LIGHT_PROFILES_FILE = "light_profiles.csv"
|
||||
# Maps discovered services to their platforms
|
||||
DISCOVERY_PLATFORMS = {
|
||||
wink.DISCOVER_LIGHTS: 'wink',
|
||||
insteon_hub.DISCOVER_LIGHTS: 'insteon_hub',
|
||||
isy994.DISCOVER_LIGHTS: 'isy994',
|
||||
discovery.SERVICE_HUE: 'hue',
|
||||
zwave.DISCOVER_LIGHTS: 'zwave',
|
||||
@@ -113,6 +117,18 @@ def turn_off(hass, entity_id=None, transition=None):
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
|
||||
|
||||
|
||||
def toggle(hass, entity_id=None, transition=None):
|
||||
""" Toggles all or specified light. """
|
||||
data = {
|
||||
key: value for key, value in [
|
||||
(ATTR_ENTITY_ID, entity_id),
|
||||
(ATTR_TRANSITION, transition),
|
||||
] if value is not None
|
||||
}
|
||||
|
||||
hass.services.call(DOMAIN, SERVICE_TOGGLE, data)
|
||||
|
||||
|
||||
# pylint: disable=too-many-branches, too-many-locals, too-many-statements
|
||||
def setup(hass, config):
|
||||
""" Exposes light control via statemachine and services. """
|
||||
@@ -164,9 +180,15 @@ def setup(hass, config):
|
||||
if transition is not None:
|
||||
params[ATTR_TRANSITION] = transition
|
||||
|
||||
service_fun = None
|
||||
if service.service == SERVICE_TURN_OFF:
|
||||
service_fun = 'turn_off'
|
||||
elif service.service == SERVICE_TOGGLE:
|
||||
service_fun = 'toggle'
|
||||
|
||||
if service_fun:
|
||||
for light in target_lights:
|
||||
light.turn_off(**params)
|
||||
getattr(light, service_fun)(**params)
|
||||
|
||||
for light in target_lights:
|
||||
if light.should_poll:
|
||||
@@ -228,7 +250,8 @@ def setup(hass, config):
|
||||
if dat.get(ATTR_FLASH) in (FLASH_SHORT, FLASH_LONG):
|
||||
params[ATTR_FLASH] = dat[ATTR_FLASH]
|
||||
|
||||
if dat.get(ATTR_EFFECT) in (EFFECT_COLORLOOP, EFFECT_WHITE):
|
||||
if dat.get(ATTR_EFFECT) in (EFFECT_COLORLOOP, EFFECT_WHITE,
|
||||
EFFECT_RANDOM):
|
||||
params[ATTR_EFFECT] = dat[ATTR_EFFECT]
|
||||
|
||||
for light in target_lights:
|
||||
@@ -247,6 +270,9 @@ def setup(hass, config):
|
||||
hass.services.register(DOMAIN, SERVICE_TURN_OFF, handle_light_service,
|
||||
descriptions.get(SERVICE_TURN_OFF))
|
||||
|
||||
hass.services.register(DOMAIN, SERVICE_TOGGLE, handle_light_service,
|
||||
descriptions.get(SERVICE_TOGGLE))
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
||||
@@ -10,17 +10,18 @@ import json
|
||||
import logging
|
||||
import os
|
||||
import socket
|
||||
import random
|
||||
from datetime import timedelta
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from homeassistant.loader import get_component
|
||||
import homeassistant.util as util
|
||||
import homeassistant.util.color as color_util
|
||||
from homeassistant.const import CONF_HOST, DEVICE_DEFAULT_NAME
|
||||
from homeassistant.const import CONF_HOST, CONF_FILENAME, DEVICE_DEFAULT_NAME
|
||||
from homeassistant.components.light import (
|
||||
Light, ATTR_BRIGHTNESS, ATTR_XY_COLOR, ATTR_COLOR_TEMP,
|
||||
ATTR_TRANSITION, ATTR_FLASH, FLASH_LONG, FLASH_SHORT,
|
||||
ATTR_EFFECT, EFFECT_COLORLOOP, ATTR_RGB_COLOR)
|
||||
ATTR_EFFECT, EFFECT_COLORLOOP, EFFECT_RANDOM, ATTR_RGB_COLOR)
|
||||
|
||||
REQUIREMENTS = ['phue==0.8']
|
||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
||||
@@ -34,9 +35,9 @@ _CONFIGURING = {}
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _find_host_from_config(hass):
|
||||
def _find_host_from_config(hass, filename=PHUE_CONFIG_FILE):
|
||||
""" Attempt to detect host based on existing configuration. """
|
||||
path = hass.config.path(PHUE_CONFIG_FILE)
|
||||
path = hass.config.path(filename)
|
||||
|
||||
if not os.path.isfile(path):
|
||||
return None
|
||||
@@ -53,13 +54,14 @@ def _find_host_from_config(hass):
|
||||
|
||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
""" Gets the Hue lights. """
|
||||
filename = config.get(CONF_FILENAME, PHUE_CONFIG_FILE)
|
||||
if discovery_info is not None:
|
||||
host = urlparse(discovery_info[1]).hostname
|
||||
else:
|
||||
host = config.get(CONF_HOST, None)
|
||||
|
||||
if host is None:
|
||||
host = _find_host_from_config(hass)
|
||||
host = _find_host_from_config(hass, filename)
|
||||
|
||||
if host is None:
|
||||
_LOGGER.error('No host found in configuration')
|
||||
@@ -69,17 +71,17 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
if host in _CONFIGURING:
|
||||
return
|
||||
|
||||
setup_bridge(host, hass, add_devices_callback)
|
||||
setup_bridge(host, hass, add_devices_callback, filename)
|
||||
|
||||
|
||||
def setup_bridge(host, hass, add_devices_callback):
|
||||
def setup_bridge(host, hass, add_devices_callback, filename):
|
||||
""" Setup a phue bridge based on host parameter. """
|
||||
import phue
|
||||
|
||||
try:
|
||||
bridge = phue.Bridge(
|
||||
host,
|
||||
config_file_path=hass.config.path(PHUE_CONFIG_FILE))
|
||||
config_file_path=hass.config.path(filename))
|
||||
except ConnectionRefusedError: # Wrong host was given
|
||||
_LOGGER.exception("Error connecting to the Hue bridge at %s", host)
|
||||
|
||||
@@ -88,7 +90,7 @@ def setup_bridge(host, hass, add_devices_callback):
|
||||
except phue.PhueRegistrationException:
|
||||
_LOGGER.warning("Connected to Hue at %s but not registered.", host)
|
||||
|
||||
request_configuration(host, hass, add_devices_callback)
|
||||
request_configuration(host, hass, add_devices_callback, filename)
|
||||
|
||||
return
|
||||
|
||||
@@ -120,10 +122,17 @@ def setup_bridge(host, hass, add_devices_callback):
|
||||
|
||||
new_lights = []
|
||||
|
||||
api_name = api.get('config').get('name')
|
||||
if api_name == 'RaspBee-GW':
|
||||
bridge_type = 'deconz'
|
||||
else:
|
||||
bridge_type = 'hue'
|
||||
|
||||
for light_id, info in api_states.items():
|
||||
if light_id not in lights:
|
||||
lights[light_id] = HueLight(int(light_id), info,
|
||||
bridge, update_lights)
|
||||
bridge, update_lights,
|
||||
bridge_type=bridge_type)
|
||||
new_lights.append(lights[light_id])
|
||||
else:
|
||||
lights[light_id].info = info
|
||||
@@ -134,7 +143,7 @@ def setup_bridge(host, hass, add_devices_callback):
|
||||
update_lights()
|
||||
|
||||
|
||||
def request_configuration(host, hass, add_devices_callback):
|
||||
def request_configuration(host, hass, add_devices_callback, filename):
|
||||
""" Request configuration steps from the user. """
|
||||
configurator = get_component('configurator')
|
||||
|
||||
@@ -148,7 +157,7 @@ def request_configuration(host, hass, add_devices_callback):
|
||||
# pylint: disable=unused-argument
|
||||
def hue_configuration_callback(data):
|
||||
""" Actions to do when our configuration callback is called. """
|
||||
setup_bridge(host, hass, add_devices_callback)
|
||||
setup_bridge(host, hass, add_devices_callback, filename)
|
||||
|
||||
_CONFIGURING[host] = configurator.request_config(
|
||||
hass, "Philips Hue", hue_configuration_callback,
|
||||
@@ -162,11 +171,14 @@ def request_configuration(host, hass, add_devices_callback):
|
||||
class HueLight(Light):
|
||||
""" Represents a Hue light """
|
||||
|
||||
def __init__(self, light_id, info, bridge, update_lights):
|
||||
# pylint: disable=too-many-arguments
|
||||
def __init__(self, light_id, info, bridge, update_lights,
|
||||
bridge_type='hue'):
|
||||
self.light_id = light_id
|
||||
self.info = info
|
||||
self.bridge = bridge
|
||||
self.update_lights = update_lights
|
||||
self.bridge_type = bridge_type
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
@@ -226,14 +238,17 @@ class HueLight(Light):
|
||||
command['alert'] = 'lselect'
|
||||
elif flash == FLASH_SHORT:
|
||||
command['alert'] = 'select'
|
||||
else:
|
||||
elif self.bridge_type == 'hue':
|
||||
command['alert'] = 'none'
|
||||
|
||||
effect = kwargs.get(ATTR_EFFECT)
|
||||
|
||||
if effect == EFFECT_COLORLOOP:
|
||||
command['effect'] = 'colorloop'
|
||||
else:
|
||||
elif effect == EFFECT_RANDOM:
|
||||
command['hue'] = random.randrange(0, 65535)
|
||||
command['sat'] = random.randrange(150, 254)
|
||||
elif self.bridge_type == 'hue':
|
||||
command['effect'] = 'none'
|
||||
|
||||
self.bridge.set_light(self.light_id, command)
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
"""
|
||||
homeassistant.components.light.insteon
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Support for Insteon Hub lights.
|
||||
"""
|
||||
|
||||
from homeassistant.components.insteon_hub import (INSTEON, InsteonToggleDevice)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Sets up the Insteon Hub light platform. """
|
||||
devs = []
|
||||
for device in INSTEON.devices:
|
||||
if device.DeviceCategory == "Switched Lighting Control":
|
||||
devs.append(InsteonToggleDevice(device))
|
||||
if device.DeviceCategory == "Dimmable Lighting Control":
|
||||
devs.append(InsteonToggleDevice(device))
|
||||
add_devices(devs)
|
||||
@@ -0,0 +1,259 @@
|
||||
"""
|
||||
homeassistant.components.light.lifx
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
LIFX platform that implements lights
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/light.lifx/
|
||||
"""
|
||||
# pylint: disable=missing-docstring
|
||||
|
||||
import logging
|
||||
import colorsys
|
||||
from homeassistant.helpers.event import track_time_change
|
||||
from homeassistant.components.light import \
|
||||
(Light, ATTR_BRIGHTNESS, ATTR_RGB_COLOR, ATTR_COLOR_TEMP, ATTR_TRANSITION)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
REQUIREMENTS = ['liffylights==0.9.0']
|
||||
DEPENDENCIES = []
|
||||
|
||||
CONF_SERVER = "server" # server address configuration item
|
||||
CONF_BROADCAST = "broadcast" # broadcast address configuration item
|
||||
SHORT_MAX = 65535 # short int maximum
|
||||
BYTE_MAX = 255 # byte maximum
|
||||
TEMP_MIN = 2500 # lifx minimum temperature
|
||||
TEMP_MAX = 9000 # lifx maximum temperature
|
||||
TEMP_MIN_HASS = 154 # home assistant minimum temperature
|
||||
TEMP_MAX_HASS = 500 # home assistant maximum temperature
|
||||
|
||||
|
||||
class LIFX():
|
||||
def __init__(self, add_devices_callback,
|
||||
server_addr=None, broadcast_addr=None):
|
||||
import liffylights
|
||||
|
||||
self._devices = []
|
||||
|
||||
self._add_devices_callback = add_devices_callback
|
||||
|
||||
self._liffylights = liffylights.LiffyLights(
|
||||
self.on_device,
|
||||
self.on_power,
|
||||
self.on_color,
|
||||
server_addr,
|
||||
broadcast_addr)
|
||||
|
||||
def find_bulb(self, ipaddr):
|
||||
bulb = None
|
||||
for device in self._devices:
|
||||
if device.ipaddr == ipaddr:
|
||||
bulb = device
|
||||
break
|
||||
return bulb
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
def on_device(self, ipaddr, name, power, hue, sat, bri, kel):
|
||||
bulb = self.find_bulb(ipaddr)
|
||||
|
||||
if bulb is None:
|
||||
bulb = LIFXLight(self._liffylights, ipaddr, name,
|
||||
power, hue, sat, bri, kel)
|
||||
self._devices.append(bulb)
|
||||
self._add_devices_callback([bulb])
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
def on_color(self, ipaddr, hue, sat, bri, kel):
|
||||
bulb = self.find_bulb(ipaddr)
|
||||
|
||||
if bulb is not None:
|
||||
bulb.set_color(hue, sat, bri, kel)
|
||||
bulb.update_ha_state()
|
||||
|
||||
def on_power(self, ipaddr, power):
|
||||
bulb = self.find_bulb(ipaddr)
|
||||
|
||||
if bulb is not None:
|
||||
bulb.set_power(power)
|
||||
bulb.update_ha_state()
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def poll(self, now):
|
||||
self.probe()
|
||||
|
||||
def probe(self, address=None):
|
||||
self._liffylights.probe(address)
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
""" Set up platform. """
|
||||
server_addr = config.get(CONF_SERVER, None)
|
||||
broadcast_addr = config.get(CONF_BROADCAST, None)
|
||||
|
||||
lifx_library = LIFX(add_devices_callback, server_addr, broadcast_addr)
|
||||
|
||||
# register our poll service
|
||||
track_time_change(hass, lifx_library.poll, second=10)
|
||||
|
||||
lifx_library.probe()
|
||||
|
||||
|
||||
def convert_rgb_to_hsv(rgb):
|
||||
""" Convert HASS RGB values to HSV values. """
|
||||
red, green, blue = [_ / BYTE_MAX for _ in rgb]
|
||||
|
||||
hue, saturation, brightness = colorsys.rgb_to_hsv(red, green, blue)
|
||||
|
||||
return [int(hue * SHORT_MAX),
|
||||
int(saturation * SHORT_MAX),
|
||||
int(brightness * SHORT_MAX)]
|
||||
|
||||
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
class LIFXLight(Light):
|
||||
""" Provides LIFX light. """
|
||||
# pylint: disable=too-many-arguments
|
||||
def __init__(self, liffy, ipaddr, name, power, hue,
|
||||
saturation, brightness, kelvin):
|
||||
_LOGGER.debug("LIFXLight: %s %s",
|
||||
ipaddr, name)
|
||||
|
||||
self._liffylights = liffy
|
||||
self._ip = ipaddr
|
||||
self.set_name(name)
|
||||
self.set_power(power)
|
||||
self.set_color(hue, saturation, brightness, kelvin)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
""" No polling needed for LIFX light. """
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" Returns the name of the device. """
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def ipaddr(self):
|
||||
""" Returns the ip of the device. """
|
||||
return self._ip
|
||||
|
||||
@property
|
||||
def rgb_color(self):
|
||||
""" Returns RGB value. """
|
||||
_LOGGER.debug("rgb_color: [%d %d %d]",
|
||||
self._rgb[0], self._rgb[1], self._rgb[2])
|
||||
|
||||
return self._rgb
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
""" Returns brightness of this light between 0..255. """
|
||||
brightness = int(self._bri / (BYTE_MAX + 1))
|
||||
|
||||
_LOGGER.debug("brightness: %d",
|
||||
brightness)
|
||||
|
||||
return brightness
|
||||
|
||||
@property
|
||||
def color_temp(self):
|
||||
""" Returns color temperature. """
|
||||
temperature = int(TEMP_MIN_HASS + (TEMP_MAX_HASS - TEMP_MIN_HASS) *
|
||||
(self._kel - TEMP_MIN) / (TEMP_MAX - TEMP_MIN))
|
||||
|
||||
_LOGGER.debug("color_temp: %d",
|
||||
temperature)
|
||||
|
||||
return temperature
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
""" True if device is on. """
|
||||
_LOGGER.debug("is_on: %d",
|
||||
self._power)
|
||||
|
||||
return self._power != 0
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
""" Turn the device on. """
|
||||
if ATTR_TRANSITION in kwargs:
|
||||
fade = kwargs[ATTR_TRANSITION] * 1000
|
||||
else:
|
||||
fade = 0
|
||||
|
||||
if ATTR_RGB_COLOR in kwargs:
|
||||
hue, saturation, brightness = \
|
||||
convert_rgb_to_hsv(kwargs[ATTR_RGB_COLOR])
|
||||
else:
|
||||
hue = self._hue
|
||||
saturation = self._sat
|
||||
brightness = self._bri
|
||||
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
brightness = kwargs[ATTR_BRIGHTNESS] * (BYTE_MAX + 1)
|
||||
else:
|
||||
brightness = self._bri
|
||||
|
||||
if ATTR_COLOR_TEMP in kwargs:
|
||||
kelvin = int(((TEMP_MAX - TEMP_MIN) *
|
||||
(kwargs[ATTR_COLOR_TEMP] - TEMP_MIN_HASS) /
|
||||
(TEMP_MAX_HASS - TEMP_MIN_HASS)) + TEMP_MIN)
|
||||
else:
|
||||
kelvin = self._kel
|
||||
|
||||
_LOGGER.debug("turn_on: %s (%d) %d %d %d %d %d",
|
||||
self._ip, self._power,
|
||||
hue, saturation, brightness, kelvin, fade)
|
||||
|
||||
if self._power == 0:
|
||||
self._liffylights.set_power(self._ip, 65535, fade)
|
||||
|
||||
self._liffylights.set_color(self._ip, hue, saturation,
|
||||
brightness, kelvin, fade)
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
""" Turn the device off. """
|
||||
if ATTR_TRANSITION in kwargs:
|
||||
fade = kwargs[ATTR_TRANSITION] * 1000
|
||||
else:
|
||||
fade = 0
|
||||
|
||||
_LOGGER.debug("turn_off: %s %d",
|
||||
self._ip, fade)
|
||||
|
||||
self._liffylights.set_power(self._ip, 0, fade)
|
||||
|
||||
def set_name(self, name):
|
||||
""" Set name. """
|
||||
self._name = name
|
||||
|
||||
def set_power(self, power):
|
||||
""" Set power state value. """
|
||||
_LOGGER.debug("set_power: %d",
|
||||
power)
|
||||
|
||||
self._power = (power != 0)
|
||||
|
||||
def set_color(self, hue, sat, bri, kel):
|
||||
""" Set color state values. """
|
||||
self._hue = hue
|
||||
self._sat = sat
|
||||
self._bri = bri
|
||||
self._kel = kel
|
||||
|
||||
red, green, blue = colorsys.hsv_to_rgb(hue / SHORT_MAX,
|
||||
sat / SHORT_MAX,
|
||||
bri / SHORT_MAX)
|
||||
|
||||
red = int(red * BYTE_MAX)
|
||||
green = int(green * BYTE_MAX)
|
||||
blue = int(blue * BYTE_MAX)
|
||||
|
||||
_LOGGER.debug("set_color: %d %d %d %d [%d %d %d]",
|
||||
hue, sat, bri, kel, red, green, blue)
|
||||
|
||||
self._rgb = [red, green, blue]
|
||||
@@ -9,12 +9,13 @@ https://home-assistant.io/components/light.rfxtrx/
|
||||
import logging
|
||||
import homeassistant.components.rfxtrx as rfxtrx
|
||||
|
||||
from homeassistant.components.light import Light
|
||||
from homeassistant.components.light import Light, ATTR_BRIGHTNESS
|
||||
from homeassistant.util import slugify
|
||||
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.components.rfxtrx import ATTR_STATE, ATTR_FIREEVENT, ATTR_PACKETID, \
|
||||
ATTR_NAME, EVENT_BUTTON_PRESSED
|
||||
from homeassistant.components.rfxtrx import (
|
||||
ATTR_STATE, ATTR_FIREEVENT, ATTR_PACKETID,
|
||||
ATTR_NAME, EVENT_BUTTON_PRESSED)
|
||||
|
||||
|
||||
DEPENDENCIES = ['rfxtrx']
|
||||
@@ -111,6 +112,7 @@ class RfxtrxLight(Light):
|
||||
self._event = event
|
||||
self._state = datas[ATTR_STATE]
|
||||
self._should_fire_event = datas[ATTR_FIREEVENT]
|
||||
self._brightness = 0
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
@@ -132,12 +134,25 @@ class RfxtrxLight(Light):
|
||||
""" True if light is on. """
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
""" Brightness of this light between 0..255. """
|
||||
return self._brightness
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
""" Turn the light on. """
|
||||
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||
|
||||
if brightness is None:
|
||||
self._brightness = 100
|
||||
else:
|
||||
self._brightness = ((brightness + 4) * 100 // 255 - 1)
|
||||
|
||||
if hasattr(self, '_event') and self._event:
|
||||
self._event.device.send_on(rfxtrx.RFXOBJECT.transport)
|
||||
self._event.device.send_dim(rfxtrx.RFXOBJECT.transport,
|
||||
self._brightness)
|
||||
|
||||
self._brightness = (self._brightness * 255 // 100)
|
||||
self._state = True
|
||||
self.update_ha_state()
|
||||
|
||||
@@ -147,5 +162,6 @@ class RfxtrxLight(Light):
|
||||
if hasattr(self, '_event') and self._event:
|
||||
self._event.device.send_off(rfxtrx.RFXOBJECT.transport)
|
||||
|
||||
self._brightness = 0
|
||||
self._state = False
|
||||
self.update_ha_state()
|
||||
|
||||
@@ -42,6 +42,7 @@ turn_on:
|
||||
description: Light effect
|
||||
values:
|
||||
- colorloop
|
||||
- random
|
||||
|
||||
turn_off:
|
||||
description: Turn a light off
|
||||
@@ -54,3 +55,15 @@ turn_off:
|
||||
transition:
|
||||
description: Duration in seconds it takes to get to next state
|
||||
example: 60
|
||||
|
||||
toggle:
|
||||
description: Toggles a light
|
||||
|
||||
fields:
|
||||
entity_id:
|
||||
description: Name(s) of entities to toggle
|
||||
example: 'light.kitchen'
|
||||
|
||||
transition:
|
||||
description: Duration in seconds it takes to get to next state
|
||||
example: 60
|
||||
|
||||
@@ -7,16 +7,15 @@ For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/light.vera/
|
||||
"""
|
||||
import logging
|
||||
import time
|
||||
|
||||
from requests.exceptions import RequestException
|
||||
from homeassistant.components.switch.vera import VeraSwitch
|
||||
|
||||
from homeassistant.components.light import ATTR_BRIGHTNESS
|
||||
|
||||
REQUIREMENTS = ['https://github.com/pavoni/home-assistant-vera-api/archive/'
|
||||
'efdba4e63d58a30bc9b36d9e01e69858af9130b8.zip'
|
||||
'#python-vera==0.1.1']
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, STATE_ON
|
||||
|
||||
REQUIREMENTS = ['pyvera==0.2.7']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -36,10 +35,19 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
|
||||
device_data = config.get('device_data', {})
|
||||
|
||||
controller = veraApi.VeraController(base_url)
|
||||
vera_controller, created = veraApi.init_controller(base_url)
|
||||
|
||||
if created:
|
||||
def stop_subscription(event):
|
||||
""" Shutdown Vera subscriptions and subscription thread on exit"""
|
||||
_LOGGER.info("Shutting down subscriptions.")
|
||||
vera_controller.stop()
|
||||
|
||||
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_subscription)
|
||||
|
||||
devices = []
|
||||
try:
|
||||
devices = controller.get_devices([
|
||||
devices = vera_controller.get_devices([
|
||||
'Switch',
|
||||
'On/Off Switch',
|
||||
'Dimmable Switch'])
|
||||
@@ -50,11 +58,11 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
|
||||
lights = []
|
||||
for device in devices:
|
||||
extra_data = device_data.get(device.deviceId, {})
|
||||
extra_data = device_data.get(device.device_id, {})
|
||||
exclude = extra_data.get('exclude', False)
|
||||
|
||||
if exclude is not True:
|
||||
lights.append(VeraLight(device, extra_data))
|
||||
lights.append(VeraLight(device, vera_controller, extra_data))
|
||||
|
||||
add_devices_callback(lights)
|
||||
|
||||
@@ -77,5 +85,5 @@ class VeraLight(VeraSwitch):
|
||||
else:
|
||||
self.vera_device.switch_on()
|
||||
|
||||
self.last_command_send = time.time()
|
||||
self.is_on_status = True
|
||||
self._state = STATE_ON
|
||||
self.update_ha_state(True)
|
||||
|
||||
@@ -12,7 +12,7 @@ from homeassistant.components.light import ATTR_BRIGHTNESS
|
||||
from homeassistant.components.wink import WinkToggleDevice
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN
|
||||
|
||||
REQUIREMENTS = ['python-wink==0.3.1']
|
||||
REQUIREMENTS = ['python-wink==0.4.2']
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
"""
|
||||
homeassistant.components.light.zigbee
|
||||
|
||||
Contains functionality to use a ZigBee device as a light.
|
||||
"""
|
||||
|
||||
from homeassistant.components.light import Light
|
||||
from homeassistant.components.zigbee import (
|
||||
ZigBeeDigitalOut, ZigBeeDigitalOutConfig)
|
||||
|
||||
|
||||
DEPENDENCIES = ["zigbee"]
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""
|
||||
Create and add an entity based on the configuration.
|
||||
"""
|
||||
add_entities([
|
||||
ZigBeeLight(hass, ZigBeeDigitalOutConfig(config))
|
||||
])
|
||||
|
||||
|
||||
class ZigBeeLight(ZigBeeDigitalOut, Light):
|
||||
"""
|
||||
Use multiple inheritance to turn an instance of ZigBeeDigitalOut into a
|
||||
Light.
|
||||
"""
|
||||
pass
|
||||
@@ -11,8 +11,10 @@ https://home-assistant.io/components/light.zwave/
|
||||
from threading import Timer
|
||||
|
||||
from homeassistant.const import STATE_ON, STATE_OFF
|
||||
from homeassistant.components.light import (Light, ATTR_BRIGHTNESS)
|
||||
import homeassistant.components.zwave as zwave
|
||||
from homeassistant.components.light import Light, ATTR_BRIGHTNESS, DOMAIN
|
||||
from homeassistant.components.zwave import (
|
||||
COMMAND_CLASS_SWITCH_MULTILEVEL, TYPE_BYTE, GENRE_USER, NETWORK,
|
||||
ATTR_NODE_ID, ATTR_VALUE_ID, ZWaveDeviceEntity)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
@@ -20,14 +22,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
||||
node = zwave.NETWORK.nodes[discovery_info[zwave.ATTR_NODE_ID]]
|
||||
value = node.values[discovery_info[zwave.ATTR_VALUE_ID]]
|
||||
node = NETWORK.nodes[discovery_info[ATTR_NODE_ID]]
|
||||
value = node.values[discovery_info[ATTR_VALUE_ID]]
|
||||
|
||||
if value.command_class != zwave.COMMAND_CLASS_SWITCH_MULTILEVEL:
|
||||
if value.command_class != COMMAND_CLASS_SWITCH_MULTILEVEL:
|
||||
return
|
||||
if value.type != zwave.TYPE_BYTE:
|
||||
if value.type != TYPE_BYTE:
|
||||
return
|
||||
if value.genre != zwave.GENRE_USER:
|
||||
if value.genre != GENRE_USER:
|
||||
return
|
||||
|
||||
value.set_change_verified(False)
|
||||
@@ -45,15 +47,14 @@ def brightness_state(value):
|
||||
return 255, STATE_OFF
|
||||
|
||||
|
||||
class ZwaveDimmer(Light):
|
||||
class ZwaveDimmer(ZWaveDeviceEntity, Light):
|
||||
""" Provides a Z-Wave dimmer. """
|
||||
# pylint: disable=too-many-arguments
|
||||
def __init__(self, value):
|
||||
from openzwave.network import ZWaveNetwork
|
||||
from pydispatch import dispatcher
|
||||
|
||||
self._value = value
|
||||
self._node = value.node
|
||||
ZWaveDeviceEntity.__init__(self, value, DOMAIN)
|
||||
|
||||
self._brightness, self._state = brightness_state(value)
|
||||
|
||||
@@ -86,18 +87,6 @@ class ZwaveDimmer(Light):
|
||||
|
||||
self.update_ha_state()
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
""" No polling needed for a light. """
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" Returns the name of the device if any. """
|
||||
name = self._node.name or "{}".format(self._node.product_name)
|
||||
|
||||
return "{}".format(name or self._value.label)
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
""" Brightness of this light between 0..255. """
|
||||
@@ -118,10 +107,10 @@ class ZwaveDimmer(Light):
|
||||
# brightness.
|
||||
brightness = (self._brightness / 255) * 99
|
||||
|
||||
if self._node.set_dimmer(self._value.value_id, brightness):
|
||||
if self._value.node.set_dimmer(self._value.value_id, brightness):
|
||||
self._state = STATE_ON
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
""" Turn the device off. """
|
||||
if self._node.set_dimmer(self._value.value_id, 0):
|
||||
if self._value.node.set_dimmer(self._value.value_id, 0):
|
||||
self._state = STATE_OFF
|
||||
|
||||
@@ -11,7 +11,7 @@ import logging
|
||||
from homeassistant.components.lock import LockDevice
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN
|
||||
|
||||
REQUIREMENTS = ['python-wink==0.3.1']
|
||||
REQUIREMENTS = ['python-wink==0.4.2']
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
|
||||
@@ -6,6 +6,7 @@ Parses events and generates a human log.
|
||||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/logbook/
|
||||
"""
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
from itertools import groupby
|
||||
import re
|
||||
@@ -14,10 +15,10 @@ from homeassistant.core import State, DOMAIN as HA_DOMAIN
|
||||
from homeassistant.const import (
|
||||
EVENT_STATE_CHANGED, STATE_NOT_HOME, STATE_ON, STATE_OFF,
|
||||
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, HTTP_BAD_REQUEST)
|
||||
from homeassistant import util
|
||||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.components import recorder, sun
|
||||
|
||||
from homeassistant.helpers.entity import split_entity_id
|
||||
from homeassistant.util import template
|
||||
|
||||
DOMAIN = "logbook"
|
||||
DEPENDENCIES = ['recorder', 'http']
|
||||
@@ -28,7 +29,9 @@ QUERY_EVENTS_BETWEEN = """
|
||||
SELECT * FROM events WHERE time_fired > ? AND time_fired < ?
|
||||
"""
|
||||
|
||||
EVENT_LOGBOOK_ENTRY = 'LOGBOOK_ENTRY'
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
EVENT_LOGBOOK_ENTRY = 'logbook_entry'
|
||||
|
||||
GROUP_BY_MINUTES = 15
|
||||
|
||||
@@ -54,8 +57,22 @@ def log_entry(hass, name, message, domain=None, entity_id=None):
|
||||
|
||||
def setup(hass, config):
|
||||
""" Listens for download events to download files. """
|
||||
hass.http.register_path('GET', URL_LOGBOOK, _handle_get_logbook)
|
||||
# create service handler
|
||||
def log_message(service):
|
||||
""" Handle sending notification message service calls. """
|
||||
message = service.data.get(ATTR_MESSAGE)
|
||||
name = service.data.get(ATTR_NAME)
|
||||
domain = service.data.get(ATTR_DOMAIN, None)
|
||||
entity_id = service.data.get(ATTR_ENTITY_ID, None)
|
||||
|
||||
if not message or not name:
|
||||
return
|
||||
|
||||
message = template.render(hass, message)
|
||||
log_entry(hass, name, message, domain, entity_id)
|
||||
|
||||
hass.http.register_path('GET', URL_LOGBOOK, _handle_get_logbook)
|
||||
hass.services.register(DOMAIN, 'log', log_message)
|
||||
return True
|
||||
|
||||
|
||||
@@ -204,12 +221,12 @@ def humanify(events):
|
||||
event.time_fired, "Home Assistant", action,
|
||||
domain=HA_DOMAIN)
|
||||
|
||||
elif event.event_type == EVENT_LOGBOOK_ENTRY:
|
||||
elif event.event_type.lower() == EVENT_LOGBOOK_ENTRY:
|
||||
domain = event.data.get(ATTR_DOMAIN)
|
||||
entity_id = event.data.get(ATTR_ENTITY_ID)
|
||||
if domain is None and entity_id is not None:
|
||||
try:
|
||||
domain = util.split_entity_id(str(entity_id))[0]
|
||||
domain = split_entity_id(str(entity_id))[0]
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
|
||||
@@ -76,8 +76,12 @@ def setup(hass, config=None):
|
||||
|
||||
logfilter[LOGGER_LOGS] = logs
|
||||
|
||||
logger = logging.getLogger('')
|
||||
logger.setLevel(logging.NOTSET)
|
||||
|
||||
# Set log filter for all log handler
|
||||
for handler in logging.root.handlers:
|
||||
handler.setLevel(logging.NOTSET)
|
||||
handler.addFilter(HomeAssistantLogFilter(logfilter))
|
||||
|
||||
return True
|
||||
|
||||
@@ -14,10 +14,10 @@ from homeassistant.config import load_yaml_config_file
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.const import (
|
||||
STATE_OFF, STATE_UNKNOWN, STATE_PLAYING,
|
||||
STATE_OFF, STATE_UNKNOWN, STATE_PLAYING, STATE_IDLE,
|
||||
ATTR_ENTITY_ID, ATTR_ENTITY_PICTURE, SERVICE_TURN_OFF, SERVICE_TURN_ON,
|
||||
SERVICE_VOLUME_UP, SERVICE_VOLUME_DOWN, SERVICE_VOLUME_SET,
|
||||
SERVICE_VOLUME_MUTE,
|
||||
SERVICE_VOLUME_MUTE, SERVICE_TOGGLE,
|
||||
SERVICE_MEDIA_PLAY_PAUSE, SERVICE_MEDIA_PLAY, SERVICE_MEDIA_PAUSE,
|
||||
SERVICE_MEDIA_NEXT_TRACK, SERVICE_MEDIA_PREVIOUS_TRACK, SERVICE_MEDIA_SEEK)
|
||||
|
||||
@@ -72,12 +72,14 @@ SUPPORT_YOUTUBE = 64
|
||||
SUPPORT_TURN_ON = 128
|
||||
SUPPORT_TURN_OFF = 256
|
||||
SUPPORT_PLAY_MEDIA = 512
|
||||
SUPPORT_VOLUME_STEP = 1024
|
||||
|
||||
YOUTUBE_COVER_URL_FORMAT = 'https://img.youtube.com/vi/{}/1.jpg'
|
||||
|
||||
SERVICE_TO_METHOD = {
|
||||
SERVICE_TURN_ON: 'turn_on',
|
||||
SERVICE_TURN_OFF: 'turn_off',
|
||||
SERVICE_TOGGLE: 'toggle',
|
||||
SERVICE_VOLUME_UP: 'volume_up',
|
||||
SERVICE_VOLUME_DOWN: 'volume_down',
|
||||
SERVICE_MEDIA_PLAY_PAUSE: 'media_play_pause',
|
||||
@@ -130,6 +132,12 @@ def turn_off(hass, entity_id=None):
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
|
||||
|
||||
|
||||
def toggle(hass, entity_id=None):
|
||||
""" Will toggle specified media player or all. """
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
hass.services.call(DOMAIN, SERVICE_TOGGLE, data)
|
||||
|
||||
|
||||
def volume_up(hass, entity_id=None):
|
||||
""" Send the media player the command for volume up. """
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
@@ -531,6 +539,13 @@ class MediaPlayerDevice(Entity):
|
||||
""" Boolean if play media command supported. """
|
||||
return bool(self.supported_media_commands & SUPPORT_PLAY_MEDIA)
|
||||
|
||||
def toggle(self):
|
||||
""" Toggles the power on the media player. """
|
||||
if self.state in [STATE_OFF, STATE_IDLE]:
|
||||
self.turn_on()
|
||||
else:
|
||||
self.turn_off()
|
||||
|
||||
def volume_up(self):
|
||||
""" volume_up media player. """
|
||||
if self.volume_level < 1:
|
||||
|
||||
@@ -20,7 +20,7 @@ from homeassistant.components.media_player import (
|
||||
SUPPORT_PREVIOUS_TRACK, SUPPORT_NEXT_TRACK,
|
||||
MEDIA_TYPE_MUSIC, MEDIA_TYPE_TVSHOW, MEDIA_TYPE_VIDEO)
|
||||
|
||||
REQUIREMENTS = ['pychromecast==0.6.13']
|
||||
REQUIREMENTS = ['pychromecast==0.7.1']
|
||||
CONF_IGNORE_CEC = 'ignore_cec'
|
||||
CAST_SPLASH = 'https://home-assistant.io/images/cast/splash.png'
|
||||
SUPPORT_CAST = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
|
||||
|
||||
@@ -14,8 +14,7 @@ from homeassistant.components.media_player import (
|
||||
MediaPlayerDevice, MEDIA_TYPE_MUSIC, MEDIA_TYPE_PLAYLIST, SUPPORT_PAUSE,
|
||||
SUPPORT_SEEK, SUPPORT_VOLUME_SET, SUPPORT_VOLUME_MUTE,
|
||||
SUPPORT_PREVIOUS_TRACK, SUPPORT_NEXT_TRACK, SUPPORT_TURN_ON,
|
||||
SUPPORT_TURN_OFF, SUPPORT_PLAY_MEDIA,
|
||||
ATTR_ENTITY_PICTURE, ATTR_SUPPORTED_MEDIA_COMMANDS)
|
||||
SUPPORT_TURN_OFF, SUPPORT_PLAY_MEDIA)
|
||||
from homeassistant.const import (
|
||||
STATE_IDLE, STATE_PLAYING, STATE_PAUSED, STATE_OFF, STATE_ON)
|
||||
|
||||
@@ -40,7 +39,10 @@ class Itunes(object):
|
||||
@property
|
||||
def _base_url(self):
|
||||
""" Returns the base url for endpoints. """
|
||||
return self.host + ":" + str(self.port)
|
||||
if self.port:
|
||||
return self.host + ":" + str(self.port)
|
||||
else:
|
||||
return self.host
|
||||
|
||||
def _request(self, method, path, params=None):
|
||||
""" Makes the actual request and returns the parsed response. """
|
||||
@@ -380,6 +382,14 @@ class AirPlayDevice(MediaPlayerDevice):
|
||||
""" Returns the name of the device. """
|
||||
return self.device_name
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
""" Icon to use in the frontend, if any. """
|
||||
if self.selected is True:
|
||||
return "mdi:volume-high"
|
||||
else:
|
||||
return "mdi:volume-off"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
""" Returns the state of the device. """
|
||||
@@ -405,23 +415,6 @@ class AirPlayDevice(MediaPlayerDevice):
|
||||
""" Flags of media commands that are supported. """
|
||||
return SUPPORT_AIRPLAY
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
""" Return the state attributes. """
|
||||
state_attr = {}
|
||||
state_attr[ATTR_SUPPORTED_MEDIA_COMMANDS] = SUPPORT_AIRPLAY
|
||||
|
||||
if self.state == STATE_OFF:
|
||||
state_attr[ATTR_ENTITY_PICTURE] = \
|
||||
('https://cloud.githubusercontent.com/assets/260/9833073'
|
||||
'/6eb5c906-5958-11e5-9b4a-472cdf36be16.png')
|
||||
else:
|
||||
state_attr[ATTR_ENTITY_PICTURE] = \
|
||||
('https://cloud.githubusercontent.com/assets/260/9833072'
|
||||
'/6eb13cce-5958-11e5-996f-e2aaefbc9a24.png')
|
||||
|
||||
return state_attr
|
||||
|
||||
def set_volume_level(self, volume):
|
||||
""" set volume level, range 0..1. """
|
||||
volume = int(volume * 100)
|
||||
|
||||
@@ -72,7 +72,8 @@ class KodiDevice(MediaPlayerDevice):
|
||||
try:
|
||||
return self._server.Player.GetActivePlayers()
|
||||
except jsonrpc_requests.jsonrpc.TransportError:
|
||||
_LOGGER.exception('Unable to fetch kodi data')
|
||||
_LOGGER.warning('Unable to fetch kodi data')
|
||||
_LOGGER.debug('Unable to fetch kodi data', exc_info=True)
|
||||
return None
|
||||
|
||||
@property
|
||||
|
||||
@@ -9,11 +9,6 @@ https://home-assistant.io/components/media_player.mpd/
|
||||
import logging
|
||||
import socket
|
||||
|
||||
try:
|
||||
import mpd
|
||||
except ImportError:
|
||||
mpd = None
|
||||
|
||||
|
||||
from homeassistant.const import (
|
||||
STATE_PLAYING, STATE_PAUSED, STATE_OFF)
|
||||
@@ -40,10 +35,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
location = config.get('location', 'MPD')
|
||||
password = config.get('password', None)
|
||||
|
||||
global mpd # pylint: disable=invalid-name
|
||||
if mpd is None:
|
||||
import mpd as mpd_
|
||||
mpd = mpd_
|
||||
import mpd
|
||||
|
||||
# pylint: disable=no-member
|
||||
try:
|
||||
@@ -82,6 +74,8 @@ class MpdDevice(MediaPlayerDevice):
|
||||
# pylint: disable=no-member, abstract-method
|
||||
|
||||
def __init__(self, server, port, location, password):
|
||||
import mpd
|
||||
|
||||
self.server = server
|
||||
self.port = port
|
||||
self._name = location
|
||||
@@ -95,6 +89,7 @@ class MpdDevice(MediaPlayerDevice):
|
||||
self.update()
|
||||
|
||||
def update(self):
|
||||
import mpd
|
||||
try:
|
||||
self.status = self.client.status()
|
||||
self.currentsong = self.client.currentsong()
|
||||
@@ -142,10 +137,14 @@ class MpdDevice(MediaPlayerDevice):
|
||||
def media_title(self):
|
||||
""" Title of current playing media. """
|
||||
name = self.currentsong.get('name', None)
|
||||
title = self.currentsong['title']
|
||||
title = self.currentsong.get('title', None)
|
||||
|
||||
if name is None:
|
||||
if name is None and title is None:
|
||||
return "None"
|
||||
elif name is None:
|
||||
return title
|
||||
elif title is None:
|
||||
return name
|
||||
else:
|
||||
return '{}: {}'.format(name, title)
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ SUPPORT_PLEX = SUPPORT_PAUSE | SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK
|
||||
|
||||
|
||||
def config_from_file(filename, config=None):
|
||||
''' Small configuration file management function'''
|
||||
""" Small configuration file management function. """
|
||||
if config:
|
||||
# We're writing configuration
|
||||
try:
|
||||
@@ -85,7 +85,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
|
||||
# pylint: disable=too-many-branches
|
||||
def setup_plexserver(host, token, hass, add_devices_callback):
|
||||
''' Setup a plexserver based on host parameter'''
|
||||
""" Setup a plexserver based on host parameter. """
|
||||
import plexapi.server
|
||||
import plexapi.exceptions
|
||||
|
||||
@@ -112,7 +112,7 @@ def setup_plexserver(host, token, hass, add_devices_callback):
|
||||
{host: {'token': token}}):
|
||||
_LOGGER.error('failed to save config file')
|
||||
|
||||
_LOGGER.info('Connected to: htts://%s', host)
|
||||
_LOGGER.info('Connected to: http://%s', host)
|
||||
|
||||
plex_clients = {}
|
||||
plex_sessions = {}
|
||||
|
||||
@@ -38,12 +38,23 @@ SUPPORT_SONOS = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE |\
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Sets up the Sonos platform. """
|
||||
import soco
|
||||
import socket
|
||||
|
||||
if discovery_info:
|
||||
add_devices([SonosDevice(hass, soco.SoCo(discovery_info))])
|
||||
return True
|
||||
|
||||
players = soco.discover()
|
||||
players = None
|
||||
hosts = config.get('hosts', None)
|
||||
if hosts:
|
||||
players = []
|
||||
for host in hosts.split(","):
|
||||
host = socket.gethostbyname(host)
|
||||
players.append(soco.SoCo(host))
|
||||
|
||||
if not players:
|
||||
players = soco.discover(interface_addr=config.get('interface_addr',
|
||||
None))
|
||||
|
||||
if not players:
|
||||
_LOGGER.warning('No Sonos speakers found.')
|
||||
|
||||
@@ -22,9 +22,9 @@ from homeassistant.const import (
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SUPPORT_SQUEEZEBOX = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE |\
|
||||
SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK | SUPPORT_SEEK |\
|
||||
SUPPORT_TURN_ON | SUPPORT_TURN_OFF
|
||||
SUPPORT_SQUEEZEBOX = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | \
|
||||
SUPPORT_VOLUME_MUTE | SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK | \
|
||||
SUPPORT_SEEK | SUPPORT_TURN_ON | SUPPORT_TURN_OFF
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
@@ -201,13 +201,20 @@ class SqueezeBoxDevice(MediaPlayerDevice):
|
||||
def media_image_url(self):
|
||||
""" Image url of current playing media. """
|
||||
if 'artwork_url' in self._status:
|
||||
return self._status['artwork_url']
|
||||
return 'http://{server}:{port}/music/current/cover.jpg?player={player}'\
|
||||
.format(
|
||||
server=self._lms.host,
|
||||
port=self._lms.http_port,
|
||||
media_url = self._status['artwork_url']
|
||||
elif 'id' in self._status:
|
||||
media_url = ('/music/{track_id}/cover.jpg').format(
|
||||
track_id=self._status['id'])
|
||||
else:
|
||||
media_url = ('/music/current/cover.jpg?player={player}').format(
|
||||
player=self._id)
|
||||
|
||||
base_url = 'http://{server}:{port}/'.format(
|
||||
server=self._lms.host,
|
||||
port=self._lms.http_port)
|
||||
|
||||
return urllib.parse.urljoin(base_url, media_url)
|
||||
|
||||
@property
|
||||
def media_title(self):
|
||||
""" Title of current playing media. """
|
||||
|
||||
@@ -0,0 +1,438 @@
|
||||
"""
|
||||
homeassistant.components.media_player.universal
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Combines multiple media players into one for a universal controller.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/media_player.universal/
|
||||
"""
|
||||
|
||||
# pylint: disable=import-error
|
||||
from copy import copy
|
||||
import logging
|
||||
|
||||
from homeassistant.helpers.event import track_state_change
|
||||
from homeassistant.helpers.service import call_from_config
|
||||
|
||||
from homeassistant.const import (
|
||||
STATE_IDLE, STATE_ON, STATE_OFF, CONF_NAME,
|
||||
ATTR_ENTITY_ID, ATTR_ENTITY_PICTURE,
|
||||
SERVICE_TURN_OFF, SERVICE_TURN_ON,
|
||||
SERVICE_VOLUME_UP, SERVICE_VOLUME_DOWN, SERVICE_VOLUME_SET,
|
||||
SERVICE_VOLUME_MUTE,
|
||||
SERVICE_MEDIA_PLAY_PAUSE, SERVICE_MEDIA_PLAY, SERVICE_MEDIA_PAUSE,
|
||||
SERVICE_MEDIA_NEXT_TRACK, SERVICE_MEDIA_PREVIOUS_TRACK, SERVICE_MEDIA_SEEK)
|
||||
|
||||
from homeassistant.components.media_player import (
|
||||
MediaPlayerDevice, DOMAIN,
|
||||
SUPPORT_VOLUME_STEP, SUPPORT_VOLUME_SET, SUPPORT_VOLUME_MUTE,
|
||||
SUPPORT_TURN_ON, SUPPORT_TURN_OFF,
|
||||
SERVICE_PLAY_MEDIA, SERVICE_YOUTUBE_VIDEO,
|
||||
ATTR_SUPPORTED_MEDIA_COMMANDS, ATTR_MEDIA_VOLUME_MUTED,
|
||||
ATTR_MEDIA_CONTENT_ID, ATTR_MEDIA_CONTENT_TYPE, ATTR_MEDIA_DURATION,
|
||||
ATTR_MEDIA_TITLE, ATTR_MEDIA_ARTIST, ATTR_MEDIA_ALBUM_NAME,
|
||||
ATTR_MEDIA_TRACK, ATTR_MEDIA_SERIES_TITLE, ATTR_MEDIA_ALBUM_ARTIST,
|
||||
ATTR_MEDIA_SEASON, ATTR_MEDIA_EPISODE, ATTR_MEDIA_CHANNEL,
|
||||
ATTR_MEDIA_PLAYLIST, ATTR_APP_ID, ATTR_APP_NAME, ATTR_MEDIA_VOLUME_LEVEL,
|
||||
ATTR_MEDIA_SEEK_POSITION)
|
||||
|
||||
ATTR_ACTIVE_CHILD = 'active_child'
|
||||
|
||||
CONF_ATTRS = 'attributes'
|
||||
CONF_CHILDREN = 'children'
|
||||
CONF_COMMANDS = 'commands'
|
||||
CONF_PLATFORM = 'platform'
|
||||
CONF_SERVICE = 'service'
|
||||
CONF_SERVICE_DATA = 'service_data'
|
||||
CONF_STATE = 'state'
|
||||
|
||||
OFF_STATES = [STATE_IDLE, STATE_OFF]
|
||||
REQUIREMENTS = []
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" sets up the universal media players """
|
||||
if not validate_config(config):
|
||||
return
|
||||
|
||||
player = UniversalMediaPlayer(hass,
|
||||
config[CONF_NAME],
|
||||
config[CONF_CHILDREN],
|
||||
config[CONF_COMMANDS],
|
||||
config[CONF_ATTRS])
|
||||
|
||||
add_devices([player])
|
||||
|
||||
|
||||
def validate_config(config):
|
||||
""" validate universal media player configuration """
|
||||
del config[CONF_PLATFORM]
|
||||
|
||||
# validate name
|
||||
if CONF_NAME not in config:
|
||||
_LOGGER.error('Universal Media Player configuration requires name')
|
||||
return False
|
||||
|
||||
validate_children(config)
|
||||
validate_commands(config)
|
||||
validate_attributes(config)
|
||||
|
||||
del_keys = []
|
||||
for key in config:
|
||||
if key not in [CONF_NAME, CONF_CHILDREN, CONF_COMMANDS, CONF_ATTRS]:
|
||||
_LOGGER.warning(
|
||||
'Universal Media Player (%s) unrecognized parameter %s',
|
||||
config[CONF_NAME], key)
|
||||
del_keys.append(key)
|
||||
for key in del_keys:
|
||||
del config[key]
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def validate_children(config):
|
||||
""" validate children """
|
||||
if CONF_CHILDREN not in config:
|
||||
_LOGGER.info(
|
||||
'No children under Universal Media Player (%s)', config[CONF_NAME])
|
||||
config[CONF_CHILDREN] = []
|
||||
elif not isinstance(config[CONF_CHILDREN], list):
|
||||
_LOGGER.warning(
|
||||
'Universal Media Player (%s) children not list in config. '
|
||||
'They will be ignored.',
|
||||
config[CONF_NAME])
|
||||
config[CONF_CHILDREN] = []
|
||||
|
||||
|
||||
def validate_commands(config):
|
||||
""" validate commands """
|
||||
if CONF_COMMANDS not in config:
|
||||
config[CONF_COMMANDS] = {}
|
||||
elif not isinstance(config[CONF_COMMANDS], dict):
|
||||
_LOGGER.warning(
|
||||
'Universal Media Player (%s) specified commands not dict in '
|
||||
'config. They will be ignored.',
|
||||
config[CONF_NAME])
|
||||
config[CONF_COMMANDS] = {}
|
||||
|
||||
|
||||
def validate_attributes(config):
|
||||
""" validate attributes """
|
||||
if CONF_ATTRS not in config:
|
||||
config[CONF_ATTRS] = {}
|
||||
elif not isinstance(config[CONF_ATTRS], dict):
|
||||
_LOGGER.warning(
|
||||
'Universal Media Player (%s) specified attributes '
|
||||
'not dict in config. They will be ignored.',
|
||||
config[CONF_NAME])
|
||||
config[CONF_ATTRS] = {}
|
||||
|
||||
for key, val in config[CONF_ATTRS].items():
|
||||
attr = val.split('|', 1)
|
||||
if len(attr) == 1:
|
||||
attr.append(None)
|
||||
config[CONF_ATTRS][key] = attr
|
||||
|
||||
|
||||
class UniversalMediaPlayer(MediaPlayerDevice):
|
||||
""" Represents a universal media player in HA """
|
||||
# pylint: disable=too-many-public-methods
|
||||
|
||||
def __init__(self, hass, name, children, commands, attributes):
|
||||
# pylint: disable=too-many-arguments
|
||||
self.hass = hass
|
||||
self._name = name
|
||||
self._children = children
|
||||
self._cmds = commands
|
||||
self._attrs = attributes
|
||||
self._child_state = None
|
||||
|
||||
def on_dependency_update(*_):
|
||||
""" update ha state when dependencies update """
|
||||
self.update_ha_state(True)
|
||||
|
||||
depend = copy(children)
|
||||
for entity in attributes.values():
|
||||
depend.append(entity[0])
|
||||
|
||||
track_state_change(hass, depend, on_dependency_update)
|
||||
|
||||
def _entity_lkp(self, entity_id, state_attr=None):
|
||||
""" Looks up an entity state from hass """
|
||||
state_obj = self.hass.states.get(entity_id)
|
||||
|
||||
if state_obj is None:
|
||||
return
|
||||
|
||||
if state_attr:
|
||||
return state_obj.attributes.get(state_attr)
|
||||
return state_obj.state
|
||||
|
||||
def _override_or_child_attr(self, attr_name):
|
||||
""" returns either the override or the active child for attr_name """
|
||||
if attr_name in self._attrs:
|
||||
return self._entity_lkp(self._attrs[attr_name][0],
|
||||
self._attrs[attr_name][1])
|
||||
|
||||
return self._child_attr(attr_name)
|
||||
|
||||
def _child_attr(self, attr_name):
|
||||
""" returns the active child's attr """
|
||||
active_child = self._child_state
|
||||
return active_child.attributes.get(attr_name) if active_child else None
|
||||
|
||||
def _call_service(self, service_name, service_data=None,
|
||||
allow_override=False):
|
||||
""" calls either a specified or active child's service """
|
||||
if allow_override and service_name in self._cmds:
|
||||
call_from_config(
|
||||
self.hass, self._cmds[service_name], blocking=True)
|
||||
return
|
||||
|
||||
if service_data is None:
|
||||
service_data = {}
|
||||
|
||||
active_child = self._child_state
|
||||
service_data[ATTR_ENTITY_ID] = active_child.entity_id
|
||||
|
||||
self.hass.services.call(DOMAIN, service_name, service_data,
|
||||
blocking=True)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
""" Indicates whether HA should poll for updates """
|
||||
return False
|
||||
|
||||
@property
|
||||
def master_state(self):
|
||||
""" gets the master state from entity or none """
|
||||
if CONF_STATE in self._attrs:
|
||||
master_state = self._entity_lkp(self._attrs[CONF_STATE][0],
|
||||
self._attrs[CONF_STATE][1])
|
||||
return master_state if master_state else STATE_OFF
|
||||
else:
|
||||
return None
|
||||
|
||||
def _cache_active_child_state(self):
|
||||
""" The state of the active child or None """
|
||||
for child_name in self._children:
|
||||
child_state = self.hass.states.get(child_name)
|
||||
if child_state and child_state.state not in OFF_STATES:
|
||||
self._child_state = child_state
|
||||
return
|
||||
self._child_state = None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" name of universal player """
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""
|
||||
Current state of media player
|
||||
|
||||
Off if master state is off
|
||||
ELSE Status of first active child
|
||||
ELSE master state or off
|
||||
"""
|
||||
master_state = self.master_state # avoid multiple lookups
|
||||
if master_state == STATE_OFF:
|
||||
return STATE_OFF
|
||||
|
||||
active_child = self._child_state
|
||||
if active_child:
|
||||
return active_child.state
|
||||
|
||||
return master_state if master_state else STATE_OFF
|
||||
|
||||
@property
|
||||
def volume_level(self):
|
||||
""" Volume level of entity specified in attributes or active child """
|
||||
return self._child_attr(ATTR_MEDIA_VOLUME_LEVEL)
|
||||
|
||||
@property
|
||||
def is_volume_muted(self):
|
||||
""" boolean if volume is muted """
|
||||
return self._override_or_child_attr(ATTR_MEDIA_VOLUME_MUTED) \
|
||||
in [True, STATE_ON]
|
||||
|
||||
@property
|
||||
def media_content_id(self):
|
||||
""" Content ID of current playing media. """
|
||||
return self._child_attr(ATTR_MEDIA_CONTENT_ID)
|
||||
|
||||
@property
|
||||
def media_content_type(self):
|
||||
""" Content type of current playing media. """
|
||||
return self._child_attr(ATTR_MEDIA_CONTENT_TYPE)
|
||||
|
||||
@property
|
||||
def media_duration(self):
|
||||
""" Duration of current playing media in seconds. """
|
||||
return self._child_attr(ATTR_MEDIA_DURATION)
|
||||
|
||||
@property
|
||||
def media_image_url(self):
|
||||
""" Image url of current playing media. """
|
||||
return self._child_attr(ATTR_ENTITY_PICTURE)
|
||||
|
||||
@property
|
||||
def media_title(self):
|
||||
""" Title of current playing media. """
|
||||
return self._child_attr(ATTR_MEDIA_TITLE)
|
||||
|
||||
@property
|
||||
def media_artist(self):
|
||||
""" Artist of current playing media. (Music track only) """
|
||||
return self._child_attr(ATTR_MEDIA_ARTIST)
|
||||
|
||||
@property
|
||||
def media_album_name(self):
|
||||
""" Album name of current playing media. (Music track only) """
|
||||
return self._child_attr(ATTR_MEDIA_ALBUM_NAME)
|
||||
|
||||
@property
|
||||
def media_album_artist(self):
|
||||
""" Album arist of current playing media. (Music track only) """
|
||||
return self._child_attr(ATTR_MEDIA_ALBUM_ARTIST)
|
||||
|
||||
@property
|
||||
def media_track(self):
|
||||
""" Track number of current playing media. (Music track only) """
|
||||
return self._child_attr(ATTR_MEDIA_TRACK)
|
||||
|
||||
@property
|
||||
def media_series_title(self):
|
||||
""" Series title of current playing media. (TV Show only)"""
|
||||
return self._child_attr(ATTR_MEDIA_SERIES_TITLE)
|
||||
|
||||
@property
|
||||
def media_season(self):
|
||||
""" Season of current playing media. (TV Show only) """
|
||||
return self._child_attr(ATTR_MEDIA_SEASON)
|
||||
|
||||
@property
|
||||
def media_episode(self):
|
||||
""" Episode of current playing media. (TV Show only) """
|
||||
return self._child_attr(ATTR_MEDIA_EPISODE)
|
||||
|
||||
@property
|
||||
def media_channel(self):
|
||||
""" Channel currently playing. """
|
||||
return self._child_attr(ATTR_MEDIA_CHANNEL)
|
||||
|
||||
@property
|
||||
def media_playlist(self):
|
||||
""" Title of Playlist currently playing. """
|
||||
return self._child_attr(ATTR_MEDIA_PLAYLIST)
|
||||
|
||||
@property
|
||||
def app_id(self):
|
||||
""" ID of the current running app. """
|
||||
return self._child_attr(ATTR_APP_ID)
|
||||
|
||||
@property
|
||||
def app_name(self):
|
||||
""" Name of the current running app. """
|
||||
return self._child_attr(ATTR_APP_NAME)
|
||||
|
||||
@property
|
||||
def supported_media_commands(self):
|
||||
""" Flags of media commands that are supported. """
|
||||
flags = self._child_attr(ATTR_SUPPORTED_MEDIA_COMMANDS) or 0
|
||||
|
||||
if SERVICE_TURN_ON in self._cmds:
|
||||
flags |= SUPPORT_TURN_ON
|
||||
if SERVICE_TURN_OFF in self._cmds:
|
||||
flags |= SUPPORT_TURN_OFF
|
||||
|
||||
if any([cmd in self._cmds for cmd in [SERVICE_VOLUME_UP,
|
||||
SERVICE_VOLUME_DOWN]]):
|
||||
flags |= SUPPORT_VOLUME_STEP
|
||||
flags &= ~SUPPORT_VOLUME_SET
|
||||
|
||||
if SERVICE_VOLUME_MUTE in self._cmds and \
|
||||
ATTR_MEDIA_VOLUME_MUTED in self._attrs:
|
||||
flags |= SUPPORT_VOLUME_MUTE
|
||||
|
||||
return flags
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
""" Extra attributes a device wants to expose. """
|
||||
active_child = self._child_state
|
||||
return {ATTR_ACTIVE_CHILD: active_child.entity_id} \
|
||||
if active_child else {}
|
||||
|
||||
def turn_on(self):
|
||||
""" turn the media player on. """
|
||||
self._call_service(SERVICE_TURN_ON, allow_override=True)
|
||||
|
||||
def turn_off(self):
|
||||
""" turn the media player off. """
|
||||
self._call_service(SERVICE_TURN_OFF, allow_override=True)
|
||||
|
||||
def mute_volume(self, is_volume_muted):
|
||||
""" mute the volume. """
|
||||
data = {ATTR_MEDIA_VOLUME_MUTED: is_volume_muted}
|
||||
self._call_service(SERVICE_VOLUME_MUTE, data, allow_override=True)
|
||||
|
||||
def set_volume_level(self, volume_level):
|
||||
""" set volume level, range 0..1. """
|
||||
data = {ATTR_MEDIA_VOLUME_LEVEL: volume_level}
|
||||
self._call_service(SERVICE_VOLUME_SET, data)
|
||||
|
||||
def media_play(self):
|
||||
""" Send play commmand. """
|
||||
self._call_service(SERVICE_MEDIA_PLAY)
|
||||
|
||||
def media_pause(self):
|
||||
""" Send pause command. """
|
||||
self._call_service(SERVICE_MEDIA_PAUSE)
|
||||
|
||||
def media_previous_track(self):
|
||||
""" Send previous track command. """
|
||||
self._call_service(SERVICE_MEDIA_PREVIOUS_TRACK)
|
||||
|
||||
def media_next_track(self):
|
||||
""" Send next track command. """
|
||||
self._call_service(SERVICE_MEDIA_NEXT_TRACK)
|
||||
|
||||
def media_seek(self, position):
|
||||
""" Send seek command. """
|
||||
data = {ATTR_MEDIA_SEEK_POSITION: position}
|
||||
self._call_service(SERVICE_MEDIA_SEEK, data)
|
||||
|
||||
def play_youtube(self, media_id):
|
||||
""" Plays a YouTube media. """
|
||||
data = {'media_id': media_id}
|
||||
self._call_service(SERVICE_YOUTUBE_VIDEO, data)
|
||||
|
||||
def play_media(self, media_type, media_id):
|
||||
""" Plays a piece of media. """
|
||||
data = {'media_type': media_type, 'media_id': media_id}
|
||||
self._call_service(SERVICE_PLAY_MEDIA, data)
|
||||
|
||||
def volume_up(self):
|
||||
""" volume_up media player. """
|
||||
self._call_service(SERVICE_VOLUME_UP, allow_override=True)
|
||||
|
||||
def volume_down(self):
|
||||
""" volume_down media player. """
|
||||
self._call_service(SERVICE_VOLUME_DOWN, allow_override=True)
|
||||
|
||||
def media_play_pause(self):
|
||||
""" media_play_pause media player. """
|
||||
self._call_service(SERVICE_MEDIA_PLAY_PAUSE)
|
||||
|
||||
def update(self):
|
||||
""" event to trigger a state update in HA """
|
||||
for child_name in self._children:
|
||||
child_state = self.hass.states.get(child_name)
|
||||
if child_state and child_state.state not in OFF_STATES:
|
||||
self._child_state = child_state
|
||||
return
|
||||
self._child_state = None
|
||||
@@ -24,13 +24,8 @@ DOMAIN = "mqtt"
|
||||
|
||||
MQTT_CLIENT = None
|
||||
|
||||
DEFAULT_PORT = 1883
|
||||
DEFAULT_KEEPALIVE = 60
|
||||
DEFAULT_QOS = 0
|
||||
DEFAULT_RETAIN = False
|
||||
|
||||
SERVICE_PUBLISH = 'publish'
|
||||
EVENT_MQTT_MESSAGE_RECEIVED = 'MQTT_MESSAGE_RECEIVED'
|
||||
EVENT_MQTT_MESSAGE_RECEIVED = 'mqtt_message_received'
|
||||
|
||||
REQUIREMENTS = ['paho-mqtt==1.1']
|
||||
|
||||
@@ -41,6 +36,16 @@ CONF_KEEPALIVE = 'keepalive'
|
||||
CONF_USERNAME = 'username'
|
||||
CONF_PASSWORD = 'password'
|
||||
CONF_CERTIFICATE = 'certificate'
|
||||
CONF_PROTOCOL = 'protocol'
|
||||
|
||||
PROTOCOL_31 = '3.1'
|
||||
PROTOCOL_311 = '3.1.1'
|
||||
|
||||
DEFAULT_PORT = 1883
|
||||
DEFAULT_KEEPALIVE = 60
|
||||
DEFAULT_QOS = 0
|
||||
DEFAULT_RETAIN = False
|
||||
DEFAULT_PROTOCOL = PROTOCOL_311
|
||||
|
||||
ATTR_TOPIC = 'topic'
|
||||
ATTR_PAYLOAD = 'payload'
|
||||
@@ -51,7 +56,7 @@ MAX_RECONNECT_WAIT = 300 # seconds
|
||||
|
||||
|
||||
def publish(hass, topic, payload, qos=None, retain=None):
|
||||
""" Send an MQTT message. """
|
||||
"""Publish message to an MQTT topic."""
|
||||
data = {
|
||||
ATTR_TOPIC: topic,
|
||||
ATTR_PAYLOAD: payload,
|
||||
@@ -66,9 +71,9 @@ def publish(hass, topic, payload, qos=None, retain=None):
|
||||
|
||||
|
||||
def subscribe(hass, topic, callback, qos=DEFAULT_QOS):
|
||||
""" Subscribe to a topic. """
|
||||
"""Subscribe to an MQTT topic."""
|
||||
def mqtt_topic_subscriber(event):
|
||||
""" Match subscribed MQTT topic. """
|
||||
"""Match subscribed MQTT topic."""
|
||||
if _match_topic(topic, event.data[ATTR_TOPIC]):
|
||||
callback(event.data[ATTR_TOPIC], event.data[ATTR_PAYLOAD],
|
||||
event.data[ATTR_QOS])
|
||||
@@ -78,8 +83,7 @@ def subscribe(hass, topic, callback, qos=DEFAULT_QOS):
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
""" Get the MQTT protocol service. """
|
||||
|
||||
"""Start the MQTT protocol service."""
|
||||
if not validate_config(config, {DOMAIN: ['broker']}, _LOGGER):
|
||||
return False
|
||||
|
||||
@@ -92,6 +96,12 @@ def setup(hass, config):
|
||||
username = util.convert(conf.get(CONF_USERNAME), str)
|
||||
password = util.convert(conf.get(CONF_PASSWORD), str)
|
||||
certificate = util.convert(conf.get(CONF_CERTIFICATE), str)
|
||||
protocol = util.convert(conf.get(CONF_PROTOCOL), str, DEFAULT_PROTOCOL)
|
||||
|
||||
if protocol not in (PROTOCOL_31, PROTOCOL_311):
|
||||
_LOGGER.error('Invalid protocol specified: %s. Allowed values: %s, %s',
|
||||
protocol, PROTOCOL_31, PROTOCOL_311)
|
||||
return False
|
||||
|
||||
# For cloudmqtt.com, secured connection, auto fill in certificate
|
||||
if certificate is None and 19999 < port < 30000 and \
|
||||
@@ -102,7 +112,7 @@ def setup(hass, config):
|
||||
global MQTT_CLIENT
|
||||
try:
|
||||
MQTT_CLIENT = MQTT(hass, broker, port, client_id, keepalive, username,
|
||||
password, certificate)
|
||||
password, certificate, protocol)
|
||||
except socket.error:
|
||||
_LOGGER.exception("Can't connect to the broker. "
|
||||
"Please check your settings and the broker "
|
||||
@@ -110,16 +120,16 @@ def setup(hass, config):
|
||||
return False
|
||||
|
||||
def stop_mqtt(event):
|
||||
""" Stop MQTT component. """
|
||||
"""Stop MQTT component."""
|
||||
MQTT_CLIENT.stop()
|
||||
|
||||
def start_mqtt(event):
|
||||
""" Launch MQTT component when Home Assistant starts up. """
|
||||
"""Launch MQTT component when Home Assistant starts up."""
|
||||
MQTT_CLIENT.start()
|
||||
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_mqtt)
|
||||
|
||||
def publish_service(call):
|
||||
""" Handle MQTT publish service calls. """
|
||||
"""Handle MQTT publish service calls."""
|
||||
msg_topic = call.data.get(ATTR_TOPIC)
|
||||
payload = call.data.get(ATTR_PAYLOAD)
|
||||
qos = call.data.get(ATTR_QOS, DEFAULT_QOS)
|
||||
@@ -137,148 +147,161 @@ def setup(hass, config):
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
class MQTT(object):
|
||||
""" Implements messaging service for MQTT. """
|
||||
"""Home Assistant MQTT client."""
|
||||
|
||||
def __init__(self, hass, broker, port, client_id, keepalive, username,
|
||||
password, certificate):
|
||||
password, certificate, protocol):
|
||||
"""Initialize Home Assistant MQTT client."""
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
self.userdata = {
|
||||
'hass': hass,
|
||||
'topics': {},
|
||||
'progress': {},
|
||||
}
|
||||
self.hass = hass
|
||||
self.topics = {}
|
||||
self.progress = {}
|
||||
|
||||
if protocol == PROTOCOL_31:
|
||||
proto = mqtt.MQTTv31
|
||||
else:
|
||||
proto = mqtt.MQTTv311
|
||||
|
||||
if client_id is None:
|
||||
self._mqttc = mqtt.Client()
|
||||
self._mqttc = mqtt.Client(protocol=proto)
|
||||
else:
|
||||
self._mqttc = mqtt.Client(client_id)
|
||||
|
||||
self._mqttc.user_data_set(self.userdata)
|
||||
self._mqttc = mqtt.Client(client_id, protocol=proto)
|
||||
|
||||
if username is not None:
|
||||
self._mqttc.username_pw_set(username, password)
|
||||
if certificate is not None:
|
||||
self._mqttc.tls_set(certificate)
|
||||
|
||||
self._mqttc.on_subscribe = _mqtt_on_subscribe
|
||||
self._mqttc.on_unsubscribe = _mqtt_on_unsubscribe
|
||||
self._mqttc.on_connect = _mqtt_on_connect
|
||||
self._mqttc.on_disconnect = _mqtt_on_disconnect
|
||||
self._mqttc.on_message = _mqtt_on_message
|
||||
self._mqttc.on_subscribe = self._mqtt_on_subscribe
|
||||
self._mqttc.on_unsubscribe = self._mqtt_on_unsubscribe
|
||||
self._mqttc.on_connect = self._mqtt_on_connect
|
||||
self._mqttc.on_disconnect = self._mqtt_on_disconnect
|
||||
self._mqttc.on_message = self._mqtt_on_message
|
||||
|
||||
self._mqttc.connect(broker, port, keepalive)
|
||||
|
||||
def publish(self, topic, payload, qos, retain):
|
||||
""" Publish a MQTT message. """
|
||||
"""Publish a MQTT message."""
|
||||
self._mqttc.publish(topic, payload, qos, retain)
|
||||
|
||||
def start(self):
|
||||
""" Run the MQTT client. """
|
||||
"""Run the MQTT client."""
|
||||
self._mqttc.loop_start()
|
||||
|
||||
def stop(self):
|
||||
""" Stop the MQTT client. """
|
||||
"""Stop the MQTT client."""
|
||||
self._mqttc.disconnect()
|
||||
self._mqttc.loop_stop()
|
||||
|
||||
def subscribe(self, topic, qos):
|
||||
""" Subscribe to a topic. """
|
||||
if topic in self.userdata['topics']:
|
||||
"""Subscribe to a topic."""
|
||||
assert isinstance(topic, str)
|
||||
|
||||
if topic in self.topics:
|
||||
return
|
||||
result, mid = self._mqttc.subscribe(topic, qos)
|
||||
_raise_on_error(result)
|
||||
self.userdata['progress'][mid] = topic
|
||||
self.userdata['topics'][topic] = None
|
||||
self.progress[mid] = topic
|
||||
self.topics[topic] = None
|
||||
|
||||
def unsubscribe(self, topic):
|
||||
""" Unsubscribe from topic. """
|
||||
"""Unsubscribe from topic."""
|
||||
result, mid = self._mqttc.unsubscribe(topic)
|
||||
_raise_on_error(result)
|
||||
self.userdata['progress'][mid] = topic
|
||||
self.progress[mid] = topic
|
||||
|
||||
def _mqtt_on_connect(self, _mqttc, _userdata, _flags, result_code):
|
||||
"""On connect callback.
|
||||
|
||||
def _mqtt_on_message(mqttc, userdata, msg):
|
||||
""" Message callback """
|
||||
userdata['hass'].bus.fire(EVENT_MQTT_MESSAGE_RECEIVED, {
|
||||
ATTR_TOPIC: msg.topic,
|
||||
ATTR_QOS: msg.qos,
|
||||
ATTR_PAYLOAD: msg.payload.decode('utf-8'),
|
||||
})
|
||||
Resubscribe to all topics we were subscribed to.
|
||||
"""
|
||||
if result_code != 0:
|
||||
_LOGGER.error('Unable to connect to the MQTT broker: %s', {
|
||||
1: 'Incorrect protocol version',
|
||||
2: 'Invalid client identifier',
|
||||
3: 'Server unavailable',
|
||||
4: 'Bad username or password',
|
||||
5: 'Not authorised'
|
||||
}.get(result_code, 'Unknown reason'))
|
||||
self._mqttc.disconnect()
|
||||
return
|
||||
|
||||
old_topics = self.topics
|
||||
|
||||
def _mqtt_on_connect(mqttc, userdata, flags, result_code):
|
||||
""" On connect, resubscribe to all topics we were subscribed to. """
|
||||
if result_code != 0:
|
||||
_LOGGER.error('Unable to connect to the MQTT broker: %s', {
|
||||
1: 'Incorrect protocol version',
|
||||
2: 'Invalid client identifier',
|
||||
3: 'Server unavailable',
|
||||
4: 'Bad username or password',
|
||||
5: 'Not authorised'
|
||||
}.get(result_code, 'Unknown reason'))
|
||||
mqttc.disconnect()
|
||||
return
|
||||
self.topics = {key: value for key, value in self.topics.items()
|
||||
if value is None}
|
||||
|
||||
old_topics = userdata['topics']
|
||||
for topic, qos in old_topics.items():
|
||||
# qos is None if we were in process of subscribing
|
||||
if qos is not None:
|
||||
self.subscribe(topic, qos)
|
||||
|
||||
userdata['topics'] = {}
|
||||
userdata['progress'] = {}
|
||||
def _mqtt_on_subscribe(self, _mqttc, _userdata, mid, granted_qos):
|
||||
"""Subscribe successful callback."""
|
||||
topic = self.progress.pop(mid, None)
|
||||
if topic is None:
|
||||
return
|
||||
self.topics[topic] = granted_qos[0]
|
||||
|
||||
for topic, qos in old_topics.items():
|
||||
# qos is None if we were in process of subscribing
|
||||
if qos is not None:
|
||||
mqttc.subscribe(topic, qos)
|
||||
def _mqtt_on_message(self, _mqttc, _userdata, msg):
|
||||
"""Message received callback."""
|
||||
self.hass.bus.fire(EVENT_MQTT_MESSAGE_RECEIVED, {
|
||||
ATTR_TOPIC: msg.topic,
|
||||
ATTR_QOS: msg.qos,
|
||||
ATTR_PAYLOAD: msg.payload.decode('utf-8'),
|
||||
})
|
||||
|
||||
def _mqtt_on_unsubscribe(self, _mqttc, _userdata, mid, granted_qos):
|
||||
"""Unsubscribe successful callback."""
|
||||
topic = self.progress.pop(mid, None)
|
||||
if topic is None:
|
||||
return
|
||||
self.topics.pop(topic, None)
|
||||
|
||||
def _mqtt_on_subscribe(mqttc, userdata, mid, granted_qos):
|
||||
""" Called when subscribe successful. """
|
||||
topic = userdata['progress'].pop(mid, None)
|
||||
if topic is None:
|
||||
return
|
||||
userdata['topics'][topic] = granted_qos
|
||||
def _mqtt_on_disconnect(self, _mqttc, _userdata, result_code):
|
||||
"""Disconnected callback."""
|
||||
self.progress = {}
|
||||
self.topics = {key: value for key, value in self.topics.items()
|
||||
if value is not None}
|
||||
|
||||
# Remove None values from topic list
|
||||
for key in list(self.topics):
|
||||
if self.topics[key] is None:
|
||||
self.topics.pop(key)
|
||||
|
||||
def _mqtt_on_unsubscribe(mqttc, userdata, mid, granted_qos):
|
||||
""" Called when subscribe successful. """
|
||||
topic = userdata['progress'].pop(mid, None)
|
||||
if topic is None:
|
||||
return
|
||||
userdata['topics'].pop(topic, None)
|
||||
# When disconnected because of calling disconnect()
|
||||
if result_code == 0:
|
||||
return
|
||||
|
||||
tries = 0
|
||||
wait_time = 0
|
||||
|
||||
def _mqtt_on_disconnect(mqttc, userdata, result_code):
|
||||
""" Called when being disconnected. """
|
||||
# When disconnected because of calling disconnect()
|
||||
if result_code == 0:
|
||||
return
|
||||
while True:
|
||||
try:
|
||||
if self._mqttc.reconnect() == 0:
|
||||
_LOGGER.info('Successfully reconnected to the MQTT server')
|
||||
break
|
||||
except socket.error:
|
||||
pass
|
||||
|
||||
tries = 0
|
||||
wait_time = 0
|
||||
|
||||
while True:
|
||||
try:
|
||||
if mqttc.reconnect() == 0:
|
||||
_LOGGER.info('Successfully reconnected to the MQTT server')
|
||||
break
|
||||
except socket.error:
|
||||
pass
|
||||
|
||||
wait_time = min(2**tries, MAX_RECONNECT_WAIT)
|
||||
_LOGGER.warning(
|
||||
'Disconnected from MQTT (%s). Trying to reconnect in %ss',
|
||||
result_code, wait_time)
|
||||
# It is ok to sleep here as we are in the MQTT thread.
|
||||
time.sleep(wait_time)
|
||||
tries += 1
|
||||
wait_time = min(2**tries, MAX_RECONNECT_WAIT)
|
||||
_LOGGER.warning(
|
||||
'Disconnected from MQTT (%s). Trying to reconnect in %ss',
|
||||
result_code, wait_time)
|
||||
# It is ok to sleep here as we are in the MQTT thread.
|
||||
time.sleep(wait_time)
|
||||
tries += 1
|
||||
|
||||
|
||||
def _raise_on_error(result):
|
||||
""" Raise error if error result. """
|
||||
"""Raise error if error result."""
|
||||
if result != 0:
|
||||
raise HomeAssistantError('Error talking to MQTT: {}'.format(result))
|
||||
|
||||
|
||||
def _match_topic(subscription, topic):
|
||||
""" Returns if topic matches subscription. """
|
||||
"""Test if topic matches subscription."""
|
||||
if subscription.endswith('#'):
|
||||
return (subscription[:-2] == topic or
|
||||
topic.startswith(subscription[:-1]))
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
"""
|
||||
homeassistant.components.mqtt_eventstream
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Connect two Home Assistant instances via MQTT..
|
||||
|
||||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/mqtt_eventstream.html
|
||||
"""
|
||||
import json
|
||||
from homeassistant.core import EventOrigin, State
|
||||
from homeassistant.components.mqtt import DOMAIN as MQTT_DOMAIN
|
||||
from homeassistant.components.mqtt import SERVICE_PUBLISH as MQTT_SVC_PUBLISH
|
||||
from homeassistant.const import (
|
||||
MATCH_ALL,
|
||||
EVENT_TIME_CHANGED,
|
||||
EVENT_CALL_SERVICE,
|
||||
EVENT_SERVICE_EXECUTED,
|
||||
EVENT_STATE_CHANGED,
|
||||
)
|
||||
import homeassistant.loader as loader
|
||||
from homeassistant.remote import JSONEncoder
|
||||
|
||||
# The domain of your component. Should be equal to the name of your component
|
||||
DOMAIN = "mqtt_eventstream"
|
||||
|
||||
# List of component names (string) your component depends upon
|
||||
DEPENDENCIES = ['mqtt']
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
""" Setup th MQTT eventstream component. """
|
||||
mqtt = loader.get_component('mqtt')
|
||||
pub_topic = config[DOMAIN].get('publish_topic', None)
|
||||
sub_topic = config[DOMAIN].get('subscribe_topic', None)
|
||||
|
||||
def _event_publisher(event):
|
||||
""" Handle events by publishing them on the MQTT queue. """
|
||||
if event.origin != EventOrigin.local:
|
||||
return
|
||||
if event.event_type == EVENT_TIME_CHANGED:
|
||||
return
|
||||
|
||||
# Filter out the events that were triggered by publishing
|
||||
# to the MQTT topic, or you will end up in an infinite loop.
|
||||
if event.event_type == EVENT_CALL_SERVICE:
|
||||
if (
|
||||
event.data.get('domain') == MQTT_DOMAIN and
|
||||
event.data.get('service') == MQTT_SVC_PUBLISH and
|
||||
event.data.get('topic') == pub_topic
|
||||
):
|
||||
return
|
||||
|
||||
# Filter out all the "event service executed" events because they
|
||||
# are only used internally by core as callbacks for blocking
|
||||
# during the interval while a service is being executed.
|
||||
# They will serve no purpose to the external system,
|
||||
# and thus are unnecessary traffic.
|
||||
# And at any rate it would cause an infinite loop to publish them
|
||||
# because publishing to an MQTT topic itself triggers one.
|
||||
if event.event_type == EVENT_SERVICE_EXECUTED:
|
||||
return
|
||||
|
||||
event_info = {'event_type': event.event_type, 'event_data': event.data}
|
||||
msg = json.dumps(event_info, cls=JSONEncoder)
|
||||
mqtt.publish(hass, pub_topic, msg)
|
||||
|
||||
# Only listen for local events if you are going to publish them
|
||||
if pub_topic:
|
||||
hass.bus.listen(MATCH_ALL, _event_publisher)
|
||||
|
||||
# Process events from a remote server that are received on a queue
|
||||
def _event_receiver(topic, payload, qos):
|
||||
"""
|
||||
Receive events published by the other HA instance and fire
|
||||
them on this hass instance.
|
||||
"""
|
||||
event = json.loads(payload)
|
||||
event_type = event.get('event_type')
|
||||
event_data = event.get('event_data')
|
||||
|
||||
# Special case handling for event STATE_CHANGED
|
||||
# We will try to convert state dicts back to State objects
|
||||
# Copied over from the _handle_api_post_events_event method
|
||||
# of the api component.
|
||||
if event_type == EVENT_STATE_CHANGED and event_data:
|
||||
for key in ('old_state', 'new_state'):
|
||||
state = State.from_dict(event_data.get(key))
|
||||
|
||||
if state:
|
||||
event_data[key] = state
|
||||
|
||||
hass.bus.fire(
|
||||
event_type,
|
||||
event_data=event_data,
|
||||
origin=EventOrigin.remote
|
||||
)
|
||||
|
||||
# Only subscribe if you specified a topic
|
||||
if sub_topic:
|
||||
mqtt.subscribe(hass, sub_topic, _event_receiver)
|
||||
|
||||
hass.states.set('{domain}.initialized'.format(domain=DOMAIN), True)
|
||||
# return boolean to indicate that initialization was successful
|
||||
return True
|
||||
@@ -0,0 +1,202 @@
|
||||
"""
|
||||
homeassistant.components.mysensors
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
MySensors component that connects to a MySensors gateway via pymysensors
|
||||
API.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/sensor.mysensors/
|
||||
"""
|
||||
import logging
|
||||
|
||||
from homeassistant.helpers import validate_config
|
||||
import homeassistant.bootstrap as bootstrap
|
||||
|
||||
from homeassistant.const import (
|
||||
EVENT_HOMEASSISTANT_START,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
EVENT_PLATFORM_DISCOVERED, ATTR_SERVICE, ATTR_DISCOVERED,
|
||||
TEMP_CELCIUS,)
|
||||
|
||||
CONF_GATEWAYS = 'gateways'
|
||||
CONF_PORT = 'port'
|
||||
CONF_DEBUG = 'debug'
|
||||
CONF_PERSISTENCE = 'persistence'
|
||||
CONF_PERSISTENCE_FILE = 'persistence_file'
|
||||
CONF_VERSION = 'version'
|
||||
DEFAULT_VERSION = '1.4'
|
||||
|
||||
DOMAIN = 'mysensors'
|
||||
DEPENDENCIES = []
|
||||
REQUIREMENTS = [
|
||||
'https://github.com/theolind/pymysensors/archive/'
|
||||
'005bff4c5ca7a56acd30e816bc3bcdb5cb2d46fd.zip#pymysensors==0.4']
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
ATTR_NODE_ID = 'node_id'
|
||||
ATTR_CHILD_ID = 'child_id'
|
||||
ATTR_PORT = 'port'
|
||||
|
||||
GATEWAYS = None
|
||||
|
||||
DISCOVER_SENSORS = "mysensors.sensors"
|
||||
DISCOVER_SWITCHES = "mysensors.switches"
|
||||
|
||||
# Maps discovered services to their platforms
|
||||
DISCOVERY_COMPONENTS = [
|
||||
('sensor', DISCOVER_SENSORS),
|
||||
('switch', DISCOVER_SWITCHES),
|
||||
]
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
"""Setup the MySensors component."""
|
||||
if not validate_config(config,
|
||||
{DOMAIN: [CONF_GATEWAYS]},
|
||||
_LOGGER):
|
||||
return False
|
||||
|
||||
import mysensors.mysensors as mysensors
|
||||
|
||||
version = str(config[DOMAIN].get(CONF_VERSION, DEFAULT_VERSION))
|
||||
is_metric = (hass.config.temperature_unit == TEMP_CELCIUS)
|
||||
|
||||
def setup_gateway(port, persistence, persistence_file, version):
|
||||
"""Return gateway after setup of the gateway."""
|
||||
gateway = mysensors.SerialGateway(port, event_callback=None,
|
||||
persistence=persistence,
|
||||
persistence_file=persistence_file,
|
||||
protocol_version=version)
|
||||
gateway.metric = is_metric
|
||||
gateway.debug = config[DOMAIN].get(CONF_DEBUG, False)
|
||||
gateway = GatewayWrapper(gateway, version)
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
gateway.event_callback = gateway.callback_factory()
|
||||
|
||||
def gw_start(event):
|
||||
"""Callback to trigger start of gateway and any persistence."""
|
||||
gateway.start()
|
||||
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP,
|
||||
lambda event: gateway.stop())
|
||||
if persistence:
|
||||
for node_id in gateway.sensors:
|
||||
gateway.event_callback('persistence', node_id)
|
||||
|
||||
hass.bus.listen_once(EVENT_HOMEASSISTANT_START, gw_start)
|
||||
|
||||
return gateway
|
||||
|
||||
# Setup all ports from config
|
||||
global GATEWAYS
|
||||
GATEWAYS = {}
|
||||
conf_gateways = config[DOMAIN][CONF_GATEWAYS]
|
||||
if isinstance(conf_gateways, dict):
|
||||
conf_gateways = [conf_gateways]
|
||||
persistence = config[DOMAIN].get(CONF_PERSISTENCE, True)
|
||||
|
||||
for index, gway in enumerate(conf_gateways):
|
||||
port = gway[CONF_PORT]
|
||||
persistence_file = gway.get(
|
||||
CONF_PERSISTENCE_FILE,
|
||||
hass.config.path('mysensors{}.pickle'.format(index + 1)))
|
||||
GATEWAYS[port] = setup_gateway(
|
||||
port, persistence, persistence_file, version)
|
||||
|
||||
for (component, discovery_service) in DISCOVERY_COMPONENTS:
|
||||
# Ensure component is loaded
|
||||
if not bootstrap.setup_component(hass, component, config):
|
||||
return False
|
||||
# Fire discovery event
|
||||
hass.bus.fire(EVENT_PLATFORM_DISCOVERED, {
|
||||
ATTR_SERVICE: discovery_service,
|
||||
ATTR_DISCOVERED: {}})
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def pf_callback_factory(map_sv_types, devices, add_devices, entity_class):
|
||||
"""Return a new callback for the platform."""
|
||||
def mysensors_callback(gateway, node_id):
|
||||
"""Callback for mysensors platform."""
|
||||
if gateway.sensors[node_id].sketch_name is None:
|
||||
_LOGGER.info('No sketch_name: node %s', node_id)
|
||||
return
|
||||
|
||||
for child in gateway.sensors[node_id].children.values():
|
||||
for value_type in child.values.keys():
|
||||
key = node_id, child.id, value_type
|
||||
if child.type not in map_sv_types or \
|
||||
value_type not in map_sv_types[child.type]:
|
||||
continue
|
||||
if key in devices:
|
||||
devices[key].update_ha_state(True)
|
||||
continue
|
||||
name = '{} {}.{}'.format(
|
||||
gateway.sensors[node_id].sketch_name, node_id, child.id)
|
||||
devices[key] = entity_class(
|
||||
gateway, node_id, child.id, name, value_type)
|
||||
|
||||
_LOGGER.info('Adding new devices: %s', devices[key])
|
||||
add_devices([devices[key]])
|
||||
if key in devices:
|
||||
devices[key].update_ha_state(True)
|
||||
return mysensors_callback
|
||||
|
||||
|
||||
class GatewayWrapper(object):
|
||||
"""Gateway wrapper class, by subclassing serial gateway."""
|
||||
|
||||
def __init__(self, gateway, version):
|
||||
"""Setup class attributes on instantiation.
|
||||
|
||||
Args:
|
||||
gateway (mysensors.SerialGateway): Gateway to wrap.
|
||||
version (str): Version of mysensors API.
|
||||
|
||||
Attributes:
|
||||
_wrapped_gateway (mysensors.SerialGateway): Wrapped gateway.
|
||||
version (str): Version of mysensors API.
|
||||
platform_callbacks (list): Callback functions, one per platform.
|
||||
const (module): Mysensors API constants.
|
||||
__initialised (bool): True if GatewayWrapper is initialised.
|
||||
"""
|
||||
self._wrapped_gateway = gateway
|
||||
self.version = version
|
||||
self.platform_callbacks = []
|
||||
self.const = self.get_const()
|
||||
self.__initialised = True
|
||||
|
||||
def __getattr__(self, name):
|
||||
"""See if this object has attribute name."""
|
||||
# Do not use hasattr, it goes into infinite recurrsion
|
||||
if name in self.__dict__:
|
||||
# this object has it
|
||||
return getattr(self, name)
|
||||
# proxy to the wrapped object
|
||||
return getattr(self._wrapped_gateway, name)
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
"""See if this object has attribute name then set to value."""
|
||||
if '_GatewayWrapper__initialised' not in self.__dict__:
|
||||
return object.__setattr__(self, name, value)
|
||||
elif name in self.__dict__:
|
||||
object.__setattr__(self, name, value)
|
||||
else:
|
||||
object.__setattr__(self._wrapped_gateway, name, value)
|
||||
|
||||
def get_const(self):
|
||||
"""Get mysensors API constants."""
|
||||
if self.version == '1.5':
|
||||
import mysensors.const_15 as const
|
||||
else:
|
||||
import mysensors.const_14 as const
|
||||
return const
|
||||
|
||||
def callback_factory(self):
|
||||
"""Return a new callback function."""
|
||||
def node_update(update_type, node_id):
|
||||
"""Callback for node updates from the MySensors gateway."""
|
||||
_LOGGER.info('update %s: node %s', update_type, node_id)
|
||||
for callback in self.platform_callbacks:
|
||||
callback(self, node_id)
|
||||
|
||||
return node_update
|
||||
@@ -0,0 +1,37 @@
|
||||
"""
|
||||
homeassistant.components.thermostat.nest
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Adds support for Nest thermostats.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/thermostat.nest/
|
||||
"""
|
||||
import logging
|
||||
|
||||
from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD)
|
||||
|
||||
REQUIREMENTS = ['python-nest==2.6.0']
|
||||
DOMAIN = 'nest'
|
||||
|
||||
NEST = None
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def setup(hass, config):
|
||||
""" Sets up the nest thermostat. """
|
||||
global NEST
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
username = config[DOMAIN].get(CONF_USERNAME)
|
||||
password = config[DOMAIN].get(CONF_PASSWORD)
|
||||
|
||||
if username is None or password is None:
|
||||
logger.error("Missing required configuration items %s or %s",
|
||||
CONF_USERNAME, CONF_PASSWORD)
|
||||
return
|
||||
|
||||
import nest
|
||||
|
||||
NEST = nest.Nest(username, password)
|
||||
|
||||
return True
|
||||
@@ -0,0 +1,51 @@
|
||||
"""
|
||||
homeassistant.components.notify.free_mobile
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Free Mobile SMS platform for notify component.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/notify.free_mobile/
|
||||
"""
|
||||
import logging
|
||||
from homeassistant.helpers import validate_config
|
||||
from homeassistant.components.notify import (
|
||||
DOMAIN, BaseNotificationService)
|
||||
from homeassistant.const import CONF_USERNAME, CONF_ACCESS_TOKEN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
REQUIREMENTS = ['freesms==0.1.0']
|
||||
|
||||
|
||||
def get_service(hass, config):
|
||||
""" Get the Free Mobile SMS notification service. """
|
||||
|
||||
if not validate_config({DOMAIN: config},
|
||||
{DOMAIN: [CONF_USERNAME,
|
||||
CONF_ACCESS_TOKEN]},
|
||||
_LOGGER):
|
||||
return None
|
||||
|
||||
return FreeSMSNotificationService(config[CONF_USERNAME],
|
||||
config[CONF_ACCESS_TOKEN])
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class FreeSMSNotificationService(BaseNotificationService):
|
||||
""" Implements notification service for the Free Mobile SMS service. """
|
||||
|
||||
def __init__(self, username, access_token):
|
||||
from freesms import FreeClient
|
||||
self.free_client = FreeClient(username, access_token)
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Send a message to the Free Mobile user cell. """
|
||||
resp = self.free_client.send_sms(message)
|
||||
|
||||
if resp.status_code == 400:
|
||||
_LOGGER.error("At least one parameter is missing")
|
||||
elif resp.status_code == 402:
|
||||
_LOGGER.error("Too much SMS send in a few time")
|
||||
elif resp.status_code == 403:
|
||||
_LOGGER.error("Wrong Username/Password")
|
||||
elif resp.status_code == 500:
|
||||
_LOGGER.error("Server error, try later")
|
||||
@@ -0,0 +1,61 @@
|
||||
"""
|
||||
homeassistant.components.notify.googlevoice
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Google Voice SMS platform for notify component.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/notify.free_mobile/
|
||||
"""
|
||||
import logging
|
||||
from homeassistant.helpers import validate_config
|
||||
from homeassistant.components.notify import (
|
||||
DOMAIN, ATTR_TARGET, BaseNotificationService)
|
||||
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
REQUIREMENTS = ['https://github.com/w1ll1am23/pygooglevoice-sms/archive/'
|
||||
'7c5ee9969b97a7992fc86a753fe9f20e3ffa3f7c.zip#'
|
||||
'pygooglevoice-sms==0.0.1']
|
||||
|
||||
|
||||
def get_service(hass, config):
|
||||
""" Get the Google Voice SMS notification service. """
|
||||
|
||||
if not validate_config({DOMAIN: config},
|
||||
{DOMAIN: [CONF_USERNAME,
|
||||
CONF_PASSWORD]},
|
||||
_LOGGER):
|
||||
return None
|
||||
|
||||
return GoogleVoiceSMSNotificationService(config[CONF_USERNAME],
|
||||
config[CONF_PASSWORD])
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class GoogleVoiceSMSNotificationService(BaseNotificationService):
|
||||
""" Implements notification service for the Google Voice SMS service. """
|
||||
|
||||
def __init__(self, username, password):
|
||||
from googlevoicesms import Voice
|
||||
self.voice = Voice()
|
||||
self.username = username
|
||||
self.password = password
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Send SMS to specified target user cell. """
|
||||
|
||||
targets = kwargs.get(ATTR_TARGET)
|
||||
|
||||
if not targets:
|
||||
_LOGGER.info('At least 1 target is required')
|
||||
return
|
||||
|
||||
if not isinstance(targets, list):
|
||||
targets = [targets]
|
||||
|
||||
self.voice.login(self.username, self.password)
|
||||
|
||||
for target in targets:
|
||||
self.voice.send_sms(target, message)
|
||||
|
||||
self.voice.logout()
|
||||
@@ -21,37 +21,38 @@ def get_service(hass, config):
|
||||
""" Get the mail notification service. """
|
||||
|
||||
if not validate_config({DOMAIN: config},
|
||||
{DOMAIN: ['server', 'port', 'sender', 'username',
|
||||
'password', 'recipient']},
|
||||
{DOMAIN: ['recipient']},
|
||||
_LOGGER):
|
||||
return None
|
||||
|
||||
smtp_server = config['server']
|
||||
port = int(config['port'])
|
||||
username = config['username']
|
||||
password = config['password']
|
||||
starttls = int(config['starttls'])
|
||||
smtp_server = config.get('server', 'localhost')
|
||||
port = int(config.get('port', '25'))
|
||||
username = config.get('username', None)
|
||||
password = config.get('password', None)
|
||||
starttls = int(config.get('starttls', 0))
|
||||
debug = config.get('debug', 0)
|
||||
|
||||
server = None
|
||||
try:
|
||||
server = smtplib.SMTP(smtp_server, port)
|
||||
server = smtplib.SMTP(smtp_server, port, timeout=5)
|
||||
server.set_debuglevel(debug)
|
||||
server.ehlo()
|
||||
if starttls == 1:
|
||||
server.starttls()
|
||||
server.ehlo()
|
||||
if username and password:
|
||||
try:
|
||||
server.login(username, password)
|
||||
|
||||
try:
|
||||
server.login(username, password)
|
||||
|
||||
except (smtplib.SMTPException, smtplib.SMTPSenderRefused):
|
||||
_LOGGER.exception("Please check your settings.")
|
||||
|
||||
return None
|
||||
except (smtplib.SMTPException, smtplib.SMTPSenderRefused):
|
||||
_LOGGER.exception("Please check your settings.")
|
||||
return None
|
||||
|
||||
except smtplib.socket.gaierror:
|
||||
_LOGGER.exception(
|
||||
"SMTP server not found. "
|
||||
"Please check the IP address or hostname of your SMTP server.")
|
||||
"SMTP server not found (%s:%s). "
|
||||
"Please check the IP address or hostname of your SMTP server.",
|
||||
smtp_server, port)
|
||||
|
||||
return None
|
||||
|
||||
@@ -68,7 +69,7 @@ def get_service(hass, config):
|
||||
|
||||
return MailNotificationService(
|
||||
smtp_server, port, config['sender'], starttls, username, password,
|
||||
config['recipient'])
|
||||
config['recipient'], debug)
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods, too-many-instance-attributes
|
||||
@@ -77,7 +78,7 @@ class MailNotificationService(BaseNotificationService):
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
def __init__(self, server, port, sender, starttls, username,
|
||||
password, recipient):
|
||||
password, recipient, debug):
|
||||
self._server = server
|
||||
self._port = port
|
||||
self._sender = sender
|
||||
@@ -85,24 +86,26 @@ class MailNotificationService(BaseNotificationService):
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.recipient = recipient
|
||||
self.debug = debug
|
||||
self.tries = 2
|
||||
self.mail = None
|
||||
|
||||
self.connect()
|
||||
|
||||
def connect(self):
|
||||
""" Connect/Authenticate to SMTP Server """
|
||||
|
||||
self.mail = smtplib.SMTP(self._server, self._port)
|
||||
self.mail.ehlo_or_helo_if_needed()
|
||||
mail = smtplib.SMTP(self._server, self._port, timeout=5)
|
||||
mail.set_debuglevel(self.debug)
|
||||
mail.ehlo_or_helo_if_needed()
|
||||
if self.starttls == 1:
|
||||
self.mail.starttls()
|
||||
self.mail.ehlo()
|
||||
self.mail.login(self.username, self.password)
|
||||
mail.starttls()
|
||||
mail.ehlo()
|
||||
if self.username and self.password:
|
||||
mail.login(self.username, self.password)
|
||||
return mail
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Send a message to a user. """
|
||||
|
||||
mail = self.connect()
|
||||
subject = kwargs.get(ATTR_TITLE)
|
||||
|
||||
msg = MIMEText(message)
|
||||
@@ -113,10 +116,13 @@ class MailNotificationService(BaseNotificationService):
|
||||
|
||||
for _ in range(self.tries):
|
||||
try:
|
||||
self.mail.sendmail(self._sender, self.recipient,
|
||||
msg.as_string())
|
||||
mail.sendmail(self._sender, self.recipient,
|
||||
msg.as_string())
|
||||
break
|
||||
except smtplib.SMTPException:
|
||||
_LOGGER.warning('SMTPException sending mail: '
|
||||
'retrying connection')
|
||||
self.connect()
|
||||
mail.quit()
|
||||
mail = self.connect()
|
||||
|
||||
mail.quit()
|
||||
|
||||
@@ -7,59 +7,62 @@ For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/notify.syslog/
|
||||
"""
|
||||
import logging
|
||||
import syslog
|
||||
|
||||
from homeassistant.helpers import validate_config
|
||||
from homeassistant.components.notify import (
|
||||
DOMAIN, ATTR_TITLE, BaseNotificationService)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
FACILITIES = {'kernel': syslog.LOG_KERN,
|
||||
'user': syslog.LOG_USER,
|
||||
'mail': syslog.LOG_MAIL,
|
||||
'daemon': syslog.LOG_DAEMON,
|
||||
'auth': syslog.LOG_KERN,
|
||||
'LPR': syslog.LOG_LPR,
|
||||
'news': syslog.LOG_NEWS,
|
||||
'uucp': syslog.LOG_UUCP,
|
||||
'cron': syslog.LOG_CRON,
|
||||
'syslog': syslog.LOG_SYSLOG,
|
||||
'local0': syslog.LOG_LOCAL0,
|
||||
'local1': syslog.LOG_LOCAL1,
|
||||
'local2': syslog.LOG_LOCAL2,
|
||||
'local3': syslog.LOG_LOCAL3,
|
||||
'local4': syslog.LOG_LOCAL4,
|
||||
'local5': syslog.LOG_LOCAL5,
|
||||
'local6': syslog.LOG_LOCAL6,
|
||||
'local7': syslog.LOG_LOCAL7}
|
||||
|
||||
OPTIONS = {'pid': syslog.LOG_PID,
|
||||
'cons': syslog.LOG_CONS,
|
||||
'ndelay': syslog.LOG_NDELAY,
|
||||
'nowait': syslog.LOG_NOWAIT,
|
||||
'perror': syslog.LOG_PERROR}
|
||||
|
||||
PRIORITIES = {5: syslog.LOG_EMERG,
|
||||
4: syslog.LOG_ALERT,
|
||||
3: syslog.LOG_CRIT,
|
||||
2: syslog.LOG_ERR,
|
||||
1: syslog.LOG_WARNING,
|
||||
0: syslog.LOG_NOTICE,
|
||||
-1: syslog.LOG_INFO,
|
||||
-2: syslog.LOG_DEBUG}
|
||||
|
||||
|
||||
def get_service(hass, config):
|
||||
""" Get the mail notification service. """
|
||||
|
||||
"""Get the syslog notification service."""
|
||||
if not validate_config({DOMAIN: config},
|
||||
{DOMAIN: ['facility', 'option', 'priority']},
|
||||
_LOGGER):
|
||||
return None
|
||||
|
||||
_facility = FACILITIES.get(config['facility'], 40)
|
||||
_option = OPTIONS.get(config['option'], 10)
|
||||
_priority = PRIORITIES.get(config['priority'], -1)
|
||||
import syslog
|
||||
|
||||
_facility = {
|
||||
'kernel': syslog.LOG_KERN,
|
||||
'user': syslog.LOG_USER,
|
||||
'mail': syslog.LOG_MAIL,
|
||||
'daemon': syslog.LOG_DAEMON,
|
||||
'auth': syslog.LOG_KERN,
|
||||
'LPR': syslog.LOG_LPR,
|
||||
'news': syslog.LOG_NEWS,
|
||||
'uucp': syslog.LOG_UUCP,
|
||||
'cron': syslog.LOG_CRON,
|
||||
'syslog': syslog.LOG_SYSLOG,
|
||||
'local0': syslog.LOG_LOCAL0,
|
||||
'local1': syslog.LOG_LOCAL1,
|
||||
'local2': syslog.LOG_LOCAL2,
|
||||
'local3': syslog.LOG_LOCAL3,
|
||||
'local4': syslog.LOG_LOCAL4,
|
||||
'local5': syslog.LOG_LOCAL5,
|
||||
'local6': syslog.LOG_LOCAL6,
|
||||
'local7': syslog.LOG_LOCAL7,
|
||||
}.get(config['facility'], 40)
|
||||
|
||||
_option = {
|
||||
'pid': syslog.LOG_PID,
|
||||
'cons': syslog.LOG_CONS,
|
||||
'ndelay': syslog.LOG_NDELAY,
|
||||
'nowait': syslog.LOG_NOWAIT,
|
||||
'perror': syslog.LOG_PERROR
|
||||
}.get(config['option'], 10)
|
||||
|
||||
_priority = {
|
||||
5: syslog.LOG_EMERG,
|
||||
4: syslog.LOG_ALERT,
|
||||
3: syslog.LOG_CRIT,
|
||||
2: syslog.LOG_ERR,
|
||||
1: syslog.LOG_WARNING,
|
||||
0: syslog.LOG_NOTICE,
|
||||
-1: syslog.LOG_INFO,
|
||||
-2: syslog.LOG_DEBUG
|
||||
}.get(config['priority'], -1)
|
||||
|
||||
return SyslogNotificationService(_facility, _option, _priority)
|
||||
|
||||
@@ -76,6 +79,7 @@ class SyslogNotificationService(BaseNotificationService):
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Send a message to a user. """
|
||||
import syslog
|
||||
|
||||
title = kwargs.get(ATTR_TITLE)
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ from homeassistant.const import CONF_API_KEY
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
REQUIREMENTS = ['python-telegram-bot==2.8.7']
|
||||
REQUIREMENTS = ['python-telegram-bot==3.2.0']
|
||||
|
||||
|
||||
def get_service(hass, config):
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
"""
|
||||
homeassistant.components.notify.twitter
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Twitter platform for notify component.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/notify.twitter/
|
||||
"""
|
||||
import logging
|
||||
from homeassistant.helpers import validate_config
|
||||
from homeassistant.components.notify import (
|
||||
DOMAIN, BaseNotificationService)
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
REQUIREMENTS = ['TwitterAPI==2.3.6']
|
||||
|
||||
CONF_CONSUMER_KEY = "consumer_key"
|
||||
CONF_CONSUMER_SECRET = "consumer_secret"
|
||||
CONF_ACCESS_TOKEN_SECRET = "access_token_secret"
|
||||
|
||||
|
||||
def get_service(hass, config):
|
||||
""" Get the Twitter notification service. """
|
||||
|
||||
if not validate_config({DOMAIN: config},
|
||||
{DOMAIN: [CONF_CONSUMER_KEY, CONF_CONSUMER_SECRET,
|
||||
CONF_ACCESS_TOKEN,
|
||||
CONF_ACCESS_TOKEN_SECRET]},
|
||||
_LOGGER):
|
||||
return None
|
||||
|
||||
return TwitterNotificationService(config[CONF_CONSUMER_KEY],
|
||||
config[CONF_CONSUMER_SECRET],
|
||||
config[CONF_ACCESS_TOKEN],
|
||||
config[CONF_ACCESS_TOKEN_SECRET])
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class TwitterNotificationService(BaseNotificationService):
|
||||
""" Implements notification service for the Twitter service. """
|
||||
|
||||
def __init__(self, consumer_key, consumer_secret, access_token_key,
|
||||
access_token_secret):
|
||||
from TwitterAPI import TwitterAPI
|
||||
self.api = TwitterAPI(consumer_key, consumer_secret, access_token_key,
|
||||
access_token_secret)
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Tweet some message. """
|
||||
resp = self.api.request('statuses/update', {'status': message})
|
||||
if resp.status_code != 200:
|
||||
import json
|
||||
obj = json.loads(resp.text)
|
||||
error_message = obj['errors'][0]['message']
|
||||
error_code = obj['errors'][0]['code']
|
||||
_LOGGER.error("Error %s : %s (Code %s)", resp.status_code,
|
||||
error_message,
|
||||
error_code)
|
||||
@@ -16,7 +16,7 @@ import json
|
||||
import atexit
|
||||
|
||||
from homeassistant.core import Event, EventOrigin, State
|
||||
import homeassistant.util.dt as date_util
|
||||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.remote import JSONEncoder
|
||||
from homeassistant.const import (
|
||||
MATCH_ALL, EVENT_TIME_CHANGED, EVENT_STATE_CHANGED,
|
||||
@@ -62,8 +62,8 @@ def row_to_state(row):
|
||||
try:
|
||||
return State(
|
||||
row[1], row[2], json.loads(row[3]),
|
||||
date_util.utc_from_timestamp(row[4]),
|
||||
date_util.utc_from_timestamp(row[5]))
|
||||
dt_util.utc_from_timestamp(row[4]),
|
||||
dt_util.utc_from_timestamp(row[5]))
|
||||
except ValueError:
|
||||
# When json.loads fails
|
||||
_LOGGER.exception("Error converting row to state: %s", row)
|
||||
@@ -74,7 +74,7 @@ def row_to_event(row):
|
||||
""" Convert a databse row to an event. """
|
||||
try:
|
||||
return Event(row[1], json.loads(row[2]), EventOrigin(row[3]),
|
||||
date_util.utc_from_timestamp(row[5]))
|
||||
dt_util.utc_from_timestamp(row[5]))
|
||||
except ValueError:
|
||||
# When json.loads fails
|
||||
_LOGGER.exception("Error converting row to event: %s", row)
|
||||
@@ -116,10 +116,10 @@ class RecorderRun(object):
|
||||
self.start = _INSTANCE.recording_start
|
||||
self.closed_incorrect = False
|
||||
else:
|
||||
self.start = date_util.utc_from_timestamp(row[1])
|
||||
self.start = dt_util.utc_from_timestamp(row[1])
|
||||
|
||||
if row[2] is not None:
|
||||
self.end = date_util.utc_from_timestamp(row[2])
|
||||
self.end = dt_util.utc_from_timestamp(row[2])
|
||||
|
||||
self.closed_incorrect = bool(row[3])
|
||||
|
||||
@@ -169,8 +169,8 @@ class Recorder(threading.Thread):
|
||||
self.queue = queue.Queue()
|
||||
self.quit_object = object()
|
||||
self.lock = threading.Lock()
|
||||
self.recording_start = date_util.utcnow()
|
||||
self.utc_offset = date_util.now().utcoffset().total_seconds()
|
||||
self.recording_start = dt_util.utcnow()
|
||||
self.utc_offset = dt_util.now().utcoffset().total_seconds()
|
||||
|
||||
def start_recording(event):
|
||||
""" Start recording. """
|
||||
@@ -217,10 +217,11 @@ class Recorder(threading.Thread):
|
||||
def shutdown(self, event):
|
||||
""" Tells the recorder to shut down. """
|
||||
self.queue.put(self.quit_object)
|
||||
self.block_till_done()
|
||||
|
||||
def record_state(self, entity_id, state, event_id):
|
||||
""" Save a state to the database. """
|
||||
now = date_util.utcnow()
|
||||
now = dt_util.utcnow()
|
||||
|
||||
# State got deleted
|
||||
if state is None:
|
||||
@@ -247,7 +248,7 @@ class Recorder(threading.Thread):
|
||||
""" Save an event to the database. """
|
||||
info = (
|
||||
event.event_type, json.dumps(event.data, cls=JSONEncoder),
|
||||
str(event.origin), date_util.utcnow(), event.time_fired,
|
||||
str(event.origin), dt_util.utcnow(), event.time_fired,
|
||||
self.utc_offset
|
||||
)
|
||||
|
||||
@@ -307,7 +308,7 @@ class Recorder(threading.Thread):
|
||||
def save_migration(migration_id):
|
||||
""" Save and commit a migration to the database. """
|
||||
cur.execute('INSERT INTO schema_version VALUES (?, ?)',
|
||||
(migration_id, date_util.utcnow()))
|
||||
(migration_id, dt_util.utcnow()))
|
||||
self.conn.commit()
|
||||
_LOGGER.info("Database migrated to version %d", migration_id)
|
||||
|
||||
@@ -420,18 +421,18 @@ class Recorder(threading.Thread):
|
||||
self.query(
|
||||
"""INSERT INTO recorder_runs (start, created, utc_offset)
|
||||
VALUES (?, ?, ?)""",
|
||||
(self.recording_start, date_util.utcnow(), self.utc_offset))
|
||||
(self.recording_start, dt_util.utcnow(), self.utc_offset))
|
||||
|
||||
def _close_run(self):
|
||||
""" Save end time for current run. """
|
||||
self.query(
|
||||
"UPDATE recorder_runs SET end=? WHERE start=?",
|
||||
(date_util.utcnow(), self.recording_start))
|
||||
(dt_util.utcnow(), self.recording_start))
|
||||
|
||||
|
||||
def _adapt_datetime(datetimestamp):
|
||||
""" Turn a datetime into an integer for in the DB. """
|
||||
return date_util.as_utc(datetimestamp.replace(microsecond=0)).timestamp()
|
||||
return dt_util.as_utc(datetimestamp.replace(microsecond=0)).timestamp()
|
||||
|
||||
|
||||
def _verify_instance():
|
||||
|
||||
@@ -48,11 +48,7 @@ def setup(hass, config):
|
||||
subscriber(event)
|
||||
|
||||
# Try to load the RFXtrx module
|
||||
try:
|
||||
import RFXtrx as rfxtrxmod
|
||||
except ImportError:
|
||||
_LOGGER.exception("Failed to import rfxtrx")
|
||||
return False
|
||||
import RFXtrx as rfxtrxmod
|
||||
|
||||
# Init the rfxtrx module
|
||||
global RFXOBJECT
|
||||
@@ -74,11 +70,7 @@ def setup(hass, config):
|
||||
|
||||
def get_rfx_object(packetid):
|
||||
""" Return the RFXObject with the packetid. """
|
||||
try:
|
||||
import RFXtrx as rfxtrxmod
|
||||
except ImportError:
|
||||
_LOGGER.exception("Failed to import rfxtrx")
|
||||
return False
|
||||
import RFXtrx as rfxtrxmod
|
||||
|
||||
binarypacket = bytearray.fromhex(packetid)
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
"""
|
||||
homeassistant.components.rpi_gpio
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Allows to control the GPIO pins of a Raspberry Pi.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/rpi_gpio/
|
||||
"""
|
||||
# pylint: disable=import-error
|
||||
import logging
|
||||
from homeassistant.const import (EVENT_HOMEASSISTANT_START,
|
||||
EVENT_HOMEASSISTANT_STOP)
|
||||
REQUIREMENTS = ['RPi.GPIO==0.6.1']
|
||||
DOMAIN = "rpi_gpio"
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# pylint: disable=no-member
|
||||
def setup(hass, config):
|
||||
""" Sets up the Raspberry PI GPIO component. """
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
def cleanup_gpio(event):
|
||||
""" Stuff to do before stop home assistant. """
|
||||
GPIO.cleanup()
|
||||
|
||||
def prepare_gpio(event):
|
||||
""" Stuff to do when home assistant starts. """
|
||||
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, cleanup_gpio)
|
||||
|
||||
hass.bus.listen_once(EVENT_HOMEASSISTANT_START, prepare_gpio)
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
return True
|
||||
|
||||
|
||||
def setup_output(port):
|
||||
""" Setup a GPIO as output. """
|
||||
import RPi.GPIO as GPIO
|
||||
GPIO.setup(port, GPIO.OUT)
|
||||
|
||||
|
||||
def setup_input(port, pull_mode):
|
||||
""" Setup a GPIO as input. """
|
||||
import RPi.GPIO as GPIO
|
||||
GPIO.setup(port, GPIO.IN,
|
||||
GPIO.PUD_DOWN if pull_mode == 'DOWN' else GPIO.PUD_UP)
|
||||
|
||||
|
||||
def write_output(port, value):
|
||||
""" Write a value to a GPIO. """
|
||||
import RPi.GPIO as GPIO
|
||||
GPIO.output(port, value)
|
||||
|
||||
|
||||
def read_input(port):
|
||||
""" Read a value from a GPIO. """
|
||||
import RPi.GPIO as GPIO
|
||||
return GPIO.input(port)
|
||||
|
||||
|
||||
def edge_detect(port, event_callback, bounce):
|
||||
""" Adds detection for RISING and FALLING events. """
|
||||
import RPi.GPIO as GPIO
|
||||
GPIO.add_event_detect(
|
||||
port,
|
||||
GPIO.BOTH,
|
||||
callback=event_callback,
|
||||
bouncetime=bounce)
|
||||
@@ -73,8 +73,9 @@ def _process_config(scene_config):
|
||||
|
||||
for entity_id in c_entities:
|
||||
if isinstance(c_entities[entity_id], dict):
|
||||
state = c_entities[entity_id].pop('state', None)
|
||||
attributes = c_entities[entity_id]
|
||||
entity_attrs = c_entities[entity_id].copy()
|
||||
state = entity_attrs.pop('state', None)
|
||||
attributes = entity_attrs
|
||||
else:
|
||||
state = c_entities[entity_id]
|
||||
attributes = {}
|
||||
|
||||
@@ -13,9 +13,10 @@ from itertools import islice
|
||||
import threading
|
||||
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.entity import ToggleEntity
|
||||
from homeassistant.helpers.entity import ToggleEntity, split_entity_id
|
||||
from homeassistant.helpers.event import track_point_in_utc_time
|
||||
from homeassistant.util import slugify, split_entity_id
|
||||
from homeassistant.helpers.service import call_from_config
|
||||
from homeassistant.util import slugify
|
||||
import homeassistant.util.dt as date_util
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, EVENT_TIME_CHANGED, STATE_ON, SERVICE_TURN_ON,
|
||||
@@ -30,7 +31,8 @@ STATE_NOT_RUNNING = 'Not Running'
|
||||
CONF_ALIAS = "alias"
|
||||
CONF_SERVICE = "service"
|
||||
CONF_SERVICE_OLD = "execute_service"
|
||||
CONF_SERVICE_DATA = "service_data"
|
||||
CONF_SERVICE_DATA = "data"
|
||||
CONF_SERVICE_DATA_OLD = "service_data"
|
||||
CONF_SEQUENCE = "sequence"
|
||||
CONF_EVENT = "event"
|
||||
CONF_EVENT_DATA = "event_data"
|
||||
@@ -81,7 +83,7 @@ def setup(hass, config):
|
||||
object_id)
|
||||
continue
|
||||
alias = cfg.get(CONF_ALIAS, object_id)
|
||||
script = Script(hass, object_id, alias, cfg[CONF_SEQUENCE])
|
||||
script = Script(object_id, alias, cfg[CONF_SEQUENCE])
|
||||
component.add_entities((script,))
|
||||
hass.services.register(DOMAIN, object_id, service_handler)
|
||||
|
||||
@@ -106,8 +108,7 @@ def setup(hass, config):
|
||||
class Script(ToggleEntity):
|
||||
""" Represents a script. """
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
def __init__(self, hass, object_id, name, sequence):
|
||||
self.hass = hass
|
||||
def __init__(self, object_id, name, sequence):
|
||||
self.entity_id = ENTITY_ID_FORMAT.format(object_id)
|
||||
self._name = name
|
||||
self.sequence = sequence
|
||||
@@ -195,13 +196,17 @@ class Script(ToggleEntity):
|
||||
|
||||
def _call_service(self, action):
|
||||
""" Calls the service specified in the action. """
|
||||
conf_service = action.get(CONF_SERVICE, action.get(CONF_SERVICE_OLD))
|
||||
self._last_action = action.get(CONF_ALIAS, conf_service)
|
||||
# Backwards compatibility
|
||||
if CONF_SERVICE not in action and CONF_SERVICE_OLD in action:
|
||||
action[CONF_SERVICE] = action[CONF_SERVICE_OLD]
|
||||
|
||||
if CONF_SERVICE_DATA not in action and CONF_SERVICE_DATA_OLD in action:
|
||||
action[CONF_SERVICE_DATA] = action[CONF_SERVICE_DATA_OLD]
|
||||
|
||||
self._last_action = action.get(CONF_ALIAS, action[CONF_SERVICE])
|
||||
_LOGGER.info("Executing script %s step %s", self._name,
|
||||
self._last_action)
|
||||
domain, service = split_entity_id(conf_service)
|
||||
data = action.get(CONF_SERVICE_DATA, {})
|
||||
self.hass.services.call(domain, service, data, True)
|
||||
call_from_config(self.hass, action, True)
|
||||
|
||||
def _fire_event(self, action):
|
||||
""" Fires an event. """
|
||||
|
||||
@@ -9,7 +9,8 @@ https://home-assistant.io/components/sensor/
|
||||
import logging
|
||||
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.components import wink, zwave, isy994, verisure, ecobee
|
||||
from homeassistant.components import (
|
||||
wink, zwave, isy994, verisure, ecobee, tellduslive, mysensors)
|
||||
|
||||
DOMAIN = 'sensor'
|
||||
SCAN_INTERVAL = 30
|
||||
@@ -22,7 +23,9 @@ DISCOVERY_PLATFORMS = {
|
||||
zwave.DISCOVER_SENSORS: 'zwave',
|
||||
isy994.DISCOVER_SENSORS: 'isy994',
|
||||
verisure.DISCOVER_SENSORS: 'verisure',
|
||||
ecobee.DISCOVER_SENSORS: 'ecobee'
|
||||
ecobee.DISCOVER_SENSORS: 'ecobee',
|
||||
tellduslive.DISCOVER_SENSORS: 'tellduslive',
|
||||
mysensors.DISCOVER_SENSORS: 'mysensors',
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ import logging
|
||||
|
||||
import requests
|
||||
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, CONF_VALUE_TEMPLATE, \
|
||||
DEVICE_DEFAULT_NAME
|
||||
from homeassistant.const import (ATTR_UNIT_OF_MEASUREMENT, CONF_VALUE_TEMPLATE,
|
||||
DEVICE_DEFAULT_NAME)
|
||||
from homeassistant.exceptions import TemplateError
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import template, Throttle
|
||||
|
||||
@@ -13,28 +13,28 @@ from homeassistant.util import Throttle
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
|
||||
REQUIREMENTS = ['blockchain==1.1.2']
|
||||
REQUIREMENTS = ['blockchain==1.2.1']
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
OPTION_TYPES = {
|
||||
'wallet': ['Wallet balance', 'BTC'],
|
||||
'exchangerate': ['Exchange rate (1 BTC)', ''],
|
||||
'exchangerate': ['Exchange rate (1 BTC)', None],
|
||||
'trade_volume_btc': ['Trade volume', 'BTC'],
|
||||
'miners_revenue_usd': ['Miners revenue', 'USD'],
|
||||
'btc_mined': ['Mined', 'BTC'],
|
||||
'trade_volume_usd': ['Trade volume', 'USD'],
|
||||
'difficulty': ['Difficulty', ''],
|
||||
'difficulty': ['Difficulty', None],
|
||||
'minutes_between_blocks': ['Time between Blocks', 'min'],
|
||||
'number_of_transactions': ['No. of Transactions', ''],
|
||||
'number_of_transactions': ['No. of Transactions', None],
|
||||
'hash_rate': ['Hash rate', 'PH/s'],
|
||||
'timestamp': ['Timestamp', ''],
|
||||
'mined_blocks': ['Minded Blocks', ''],
|
||||
'blocks_size': ['Block size', ''],
|
||||
'timestamp': ['Timestamp', None],
|
||||
'mined_blocks': ['Minded Blocks', None],
|
||||
'blocks_size': ['Block size', None],
|
||||
'total_fees_btc': ['Total fees', 'BTC'],
|
||||
'total_btc_sent': ['Total sent', 'BTC'],
|
||||
'estimated_btc_sent': ['Estimated sent', 'BTC'],
|
||||
'total_btc': ['Total', 'BTC'],
|
||||
'total_blocks': ['Total Blocks', ''],
|
||||
'next_retarget': ['Next retarget', ''],
|
||||
'total_blocks': ['Total Blocks', None],
|
||||
'next_retarget': ['Next retarget', None],
|
||||
'estimated_transaction_volume_usd': ['Est. Transaction volume', 'USD'],
|
||||
'miners_revenue_btc': ['Miners revenue', 'BTC'],
|
||||
'market_price_usd': ['Market price', 'USD']
|
||||
@@ -47,16 +47,8 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120)
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Get the Bitcoin sensor. """
|
||||
|
||||
try:
|
||||
from blockchain.wallet import Wallet
|
||||
from blockchain import exchangerates, exceptions
|
||||
|
||||
except ImportError:
|
||||
_LOGGER.exception(
|
||||
"Unable to import blockchain. "
|
||||
"Did you maybe not install the 'blockchain' package?")
|
||||
|
||||
return False
|
||||
from blockchain.wallet import Wallet
|
||||
from blockchain import exchangerates, exceptions
|
||||
|
||||
wallet_id = config.get('wallet', None)
|
||||
password = config.get('password', None)
|
||||
|
||||
@@ -10,7 +10,7 @@ import logging
|
||||
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
REQUIREMENTS = ['py-cpuinfo==0.1.6']
|
||||
REQUIREMENTS = ['py-cpuinfo==0.1.8']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -25,14 +25,6 @@ ATTR_HZ = 'GHz Advertised'
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Sets up the CPU speed sensor. """
|
||||
|
||||
try:
|
||||
import cpuinfo # noqa
|
||||
except ImportError:
|
||||
_LOGGER.exception(
|
||||
"Unable to import cpuinfo. "
|
||||
"Did you maybe not install the 'py-cpuinfo' package?")
|
||||
return False
|
||||
|
||||
add_devices([CpuSpeedSensor(config.get('name', DEFAULT_NAME))])
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ REQUIREMENTS = ['http://github.com/mala-zaba/Adafruit_Python_DHT/archive/'
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
SENSOR_TYPES = {
|
||||
'temperature': ['Temperature', ''],
|
||||
'temperature': ['Temperature', None],
|
||||
'humidity': ['Humidity', '%']
|
||||
}
|
||||
# Return cached results if last scan was less then this time ago
|
||||
@@ -31,15 +31,8 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=30)
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Get the DHT sensor. """
|
||||
|
||||
try:
|
||||
import Adafruit_DHT
|
||||
|
||||
except ImportError:
|
||||
_LOGGER.exception(
|
||||
"Unable to import Adafruit_DHT. "
|
||||
"Did you maybe not install the 'Adafruit_DHT' package?")
|
||||
|
||||
return False
|
||||
# pylint: disable=import-error
|
||||
import Adafruit_DHT
|
||||
|
||||
SENSOR_TYPES['temperature'][1] = hass.config.temperature_unit
|
||||
unit = hass.config.temperature_unit
|
||||
|
||||
@@ -36,7 +36,7 @@ DEPENDENCIES = ['ecobee']
|
||||
SENSOR_TYPES = {
|
||||
'temperature': ['Temperature', TEMP_FAHRENHEIT],
|
||||
'humidity': ['Humidity', '%'],
|
||||
'occupancy': ['Occupancy', '']
|
||||
'occupancy': ['Occupancy', None]
|
||||
}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -16,8 +16,8 @@ _LOGGER = logging.getLogger(__name__)
|
||||
_RESOURCE = 'https://engage.efergy.com/mobile_proxy/'
|
||||
SENSOR_TYPES = {
|
||||
'instant_readings': ['Energy Usage', 'kW'],
|
||||
'budget': ['Energy Budget', ''],
|
||||
'cost': ['Energy Cost', ''],
|
||||
'budget': ['Energy Budget', None],
|
||||
'cost': ['Energy Cost', None],
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -53,6 +53,11 @@ class EliqSensor(Entity):
|
||||
""" Returns the name. """
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
""" Returns icon. """
|
||||
return "mdi:speedometer"
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
""" Unit of measurement of this entity, if any. """
|
||||
@@ -65,5 +70,8 @@ class EliqSensor(Entity):
|
||||
|
||||
def update(self):
|
||||
""" Gets the latest data. """
|
||||
response = self.api.get_data_now(channelid=self.channel_id)
|
||||
self._state = int(response.power)
|
||||
try:
|
||||
response = self.api.get_data_now(channelid=self.channel_id)
|
||||
self._state = int(response.power)
|
||||
except TypeError: # raised by eliqonline library on any HTTP error
|
||||
pass
|
||||
|
||||
@@ -19,13 +19,13 @@ _LOGGER = logging.getLogger(__name__)
|
||||
# Sensor types are defined like so:
|
||||
# Name, si unit, us unit, ca unit, uk unit, uk2 unit
|
||||
SENSOR_TYPES = {
|
||||
'summary': ['Summary', '', '', '', '', ''],
|
||||
'icon': ['Icon', '', '', '', '', ''],
|
||||
'summary': ['Summary', None, None, None, None, None],
|
||||
'icon': ['Icon', None, None, None, None, None],
|
||||
'nearest_storm_distance': ['Nearest Storm Distance',
|
||||
'km', 'm', 'km', 'km', 'm'],
|
||||
'nearest_storm_bearing': ['Nearest Storm Bearing',
|
||||
'°', '°', '°', '°', '°'],
|
||||
'precip_type': ['Precip', '', '', '', '', ''],
|
||||
'precip_type': ['Precip', None, None, None, None, None],
|
||||
'precip_intensity': ['Precip Intensity', 'mm', 'in', 'mm', 'mm', 'mm'],
|
||||
'precip_probability': ['Precip Probability', '%', '%', '%', '%', '%'],
|
||||
'temperature': ['Temperature', '°C', '°F', '°C', '°C', '°C'],
|
||||
|
||||
@@ -31,11 +31,11 @@ SENSOR_TYPES = {
|
||||
'swap_use_percent': ['Swap Use', '%'],
|
||||
'swap_use': ['Swap Use', 'GiB'],
|
||||
'swap_free': ['Swap Free', 'GiB'],
|
||||
'processor_load': ['CPU Load', ''],
|
||||
'process_running': ['Running', ''],
|
||||
'process_total': ['Total', ''],
|
||||
'process_thread': ['Thread', ''],
|
||||
'process_sleeping': ['Sleeping', '']
|
||||
'processor_load': ['CPU Load', None],
|
||||
'process_running': ['Running', None],
|
||||
'process_total': ['Total', None],
|
||||
'process_thread': ['Thread', None],
|
||||
'process_sleeping': ['Sleeping', None]
|
||||
}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -11,146 +11,193 @@ import logging
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from homeassistant.const import (
|
||||
ATTR_BATTERY_LEVEL, EVENT_HOMEASSISTANT_STOP,
|
||||
TEMP_CELCIUS, TEMP_FAHRENHEIT,
|
||||
ATTR_BATTERY_LEVEL,
|
||||
TEMP_CELCIUS,
|
||||
STATE_ON, STATE_OFF)
|
||||
|
||||
CONF_PORT = "port"
|
||||
CONF_DEBUG = "debug"
|
||||
CONF_PERSISTENCE = "persistence"
|
||||
CONF_PERSISTENCE_FILE = "persistence_file"
|
||||
CONF_VERSION = "version"
|
||||
|
||||
ATTR_NODE_ID = "node_id"
|
||||
ATTR_CHILD_ID = "child_id"
|
||||
import homeassistant.components.mysensors as mysensors
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
REQUIREMENTS = ['https://github.com/theolind/pymysensors/archive/'
|
||||
'd4b809c2167650691058d1e29bfd2c4b1792b4b0.zip'
|
||||
'#pymysensors==0.3']
|
||||
DEPENDENCIES = []
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Setup the mysensors platform. """
|
||||
"""Setup the mysensors platform for sensors."""
|
||||
# Only act if loaded via mysensors by discovery event.
|
||||
# Otherwise gateway is not setup.
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
||||
import mysensors.mysensors as mysensors
|
||||
import mysensors.const_14 as const
|
||||
for gateway in mysensors.GATEWAYS.values():
|
||||
# Define the S_TYPES and V_TYPES that the platform should handle as
|
||||
# states. Map them in a defaultdict(list).
|
||||
pres = gateway.const.Presentation
|
||||
set_req = gateway.const.SetReq
|
||||
map_sv_types = {
|
||||
pres.S_DOOR: [set_req.V_TRIPPED],
|
||||
pres.S_MOTION: [set_req.V_TRIPPED],
|
||||
pres.S_SMOKE: [set_req.V_TRIPPED],
|
||||
pres.S_TEMP: [set_req.V_TEMP],
|
||||
pres.S_HUM: [set_req.V_HUM],
|
||||
pres.S_BARO: [set_req.V_PRESSURE, set_req.V_FORECAST],
|
||||
pres.S_WIND: [set_req.V_WIND, set_req.V_GUST],
|
||||
pres.S_RAIN: [set_req.V_RAIN, set_req.V_RAINRATE],
|
||||
pres.S_UV: [set_req.V_UV],
|
||||
pres.S_WEIGHT: [set_req.V_WEIGHT, set_req.V_IMPEDANCE],
|
||||
pres.S_POWER: [set_req.V_WATT, set_req.V_KWH],
|
||||
pres.S_DISTANCE: [set_req.V_DISTANCE],
|
||||
pres.S_LIGHT_LEVEL: [set_req.V_LIGHT_LEVEL],
|
||||
pres.S_IR: [set_req.V_IR_SEND, set_req.V_IR_RECEIVE],
|
||||
pres.S_WATER: [set_req.V_FLOW, set_req.V_VOLUME],
|
||||
pres.S_CUSTOM: [set_req.V_VAR1,
|
||||
set_req.V_VAR2,
|
||||
set_req.V_VAR3,
|
||||
set_req.V_VAR4,
|
||||
set_req.V_VAR5],
|
||||
pres.S_SCENE_CONTROLLER: [set_req.V_SCENE_ON,
|
||||
set_req.V_SCENE_OFF],
|
||||
}
|
||||
if float(gateway.version) < 1.5:
|
||||
map_sv_types.update({
|
||||
pres.S_AIR_QUALITY: [set_req.V_DUST_LEVEL],
|
||||
pres.S_DUST: [set_req.V_DUST_LEVEL],
|
||||
})
|
||||
if float(gateway.version) >= 1.5:
|
||||
map_sv_types.update({
|
||||
pres.S_COLOR_SENSOR: [set_req.V_RGB],
|
||||
pres.S_MULTIMETER: [set_req.V_VOLTAGE,
|
||||
set_req.V_CURRENT,
|
||||
set_req.V_IMPEDANCE],
|
||||
pres.S_SPRINKLER: [set_req.V_TRIPPED],
|
||||
pres.S_WATER_LEAK: [set_req.V_TRIPPED],
|
||||
pres.S_SOUND: [set_req.V_TRIPPED, set_req.V_LEVEL],
|
||||
pres.S_VIBRATION: [set_req.V_TRIPPED, set_req.V_LEVEL],
|
||||
pres.S_MOISTURE: [set_req.V_TRIPPED, set_req.V_LEVEL],
|
||||
pres.S_AIR_QUALITY: [set_req.V_LEVEL],
|
||||
pres.S_DUST: [set_req.V_LEVEL],
|
||||
})
|
||||
map_sv_types[pres.S_LIGHT_LEVEL].append(set_req.V_LEVEL)
|
||||
|
||||
devices = {} # keep track of devices added to HA
|
||||
# Just assume celcius means that the user wants metric for now.
|
||||
# It may make more sense to make this a global config option in the future.
|
||||
is_metric = (hass.config.temperature_unit == TEMP_CELCIUS)
|
||||
|
||||
def sensor_update(update_type, nid):
|
||||
""" Callback for sensor updates from the MySensors gateway. """
|
||||
_LOGGER.info("sensor_update %s: node %s", update_type, nid)
|
||||
sensor = gateway.sensors[nid]
|
||||
if sensor.sketch_name is None:
|
||||
return
|
||||
if nid not in devices:
|
||||
devices[nid] = {}
|
||||
|
||||
node = devices[nid]
|
||||
new_devices = []
|
||||
for child_id, child in sensor.children.items():
|
||||
if child_id not in node:
|
||||
node[child_id] = {}
|
||||
for value_type, value in child.values.items():
|
||||
if value_type not in node[child_id]:
|
||||
name = '{} {}.{}'.format(sensor.sketch_name, nid, child.id)
|
||||
node[child_id][value_type] = \
|
||||
MySensorsNodeValue(
|
||||
nid, child_id, name, value_type, is_metric, const)
|
||||
new_devices.append(node[child_id][value_type])
|
||||
else:
|
||||
node[child_id][value_type].update_sensor(
|
||||
value, sensor.battery_level)
|
||||
|
||||
if new_devices:
|
||||
_LOGGER.info("adding new devices: %s", new_devices)
|
||||
add_devices(new_devices)
|
||||
|
||||
port = config.get(CONF_PORT)
|
||||
if port is None:
|
||||
_LOGGER.error("Missing required key 'port'")
|
||||
return False
|
||||
|
||||
persistence = config.get(CONF_PERSISTENCE, True)
|
||||
persistence_file = config.get(CONF_PERSISTENCE_FILE,
|
||||
hass.config.path('mysensors.pickle'))
|
||||
version = config.get(CONF_VERSION, '1.4')
|
||||
|
||||
gateway = mysensors.SerialGateway(port, sensor_update,
|
||||
persistence=persistence,
|
||||
persistence_file=persistence_file,
|
||||
protocol_version=version)
|
||||
gateway.metric = is_metric
|
||||
gateway.debug = config.get(CONF_DEBUG, False)
|
||||
gateway.start()
|
||||
|
||||
if persistence:
|
||||
for nid in gateway.sensors:
|
||||
sensor_update('sensor_update', nid)
|
||||
|
||||
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP,
|
||||
lambda event: gateway.stop())
|
||||
devices = {}
|
||||
gateway.platform_callbacks.append(mysensors.pf_callback_factory(
|
||||
map_sv_types, devices, add_devices, MySensorsSensor))
|
||||
|
||||
|
||||
class MySensorsNodeValue(Entity):
|
||||
""" Represents the value of a MySensors child node. """
|
||||
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
||||
def __init__(self, node_id, child_id, name, value_type, metric, const):
|
||||
self._name = name
|
||||
class MySensorsSensor(Entity):
|
||||
"""Represent the value of a MySensors child node."""
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
|
||||
def __init__(self, gateway, node_id, child_id, name, value_type):
|
||||
"""Setup class attributes on instantiation.
|
||||
|
||||
Args:
|
||||
gateway (GatewayWrapper): Gateway object.
|
||||
node_id (str): Id of node.
|
||||
child_id (str): Id of child.
|
||||
name (str): Entity name.
|
||||
value_type (str): Value type of child. Value is entity state.
|
||||
|
||||
Attributes:
|
||||
gateway (GatewayWrapper): Gateway object.
|
||||
node_id (str): Id of node.
|
||||
child_id (str): Id of child.
|
||||
_name (str): Entity name.
|
||||
value_type (str): Value type of child. Value is entity state.
|
||||
battery_level (int): Node battery level.
|
||||
_values (dict): Child values. Non state values set as state attributes.
|
||||
"""
|
||||
self.gateway = gateway
|
||||
self.node_id = node_id
|
||||
self.child_id = child_id
|
||||
self.battery_level = 0
|
||||
self._name = name
|
||||
self.value_type = value_type
|
||||
self.metric = metric
|
||||
self._value = ''
|
||||
self.const = const
|
||||
self.battery_level = 0
|
||||
self._values = {}
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
""" MySensor gateway pushes its state to HA. """
|
||||
"""MySensor gateway pushes its state to HA."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" The name of this sensor. """
|
||||
"""The name of this entity."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
""" Returns the state of the device. """
|
||||
return self._value
|
||||
"""Return the state of the device."""
|
||||
if not self._values:
|
||||
return ''
|
||||
return self._values[self.value_type]
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
""" Unit of measurement of this entity. """
|
||||
if self.value_type == self.const.SetReq.V_TEMP:
|
||||
return TEMP_CELCIUS if self.metric else TEMP_FAHRENHEIT
|
||||
elif self.value_type == self.const.SetReq.V_HUM or \
|
||||
self.value_type == self.const.SetReq.V_DIMMER or \
|
||||
self.value_type == self.const.SetReq.V_LIGHT_LEVEL:
|
||||
return '%'
|
||||
return None
|
||||
"""Unit of measurement of this entity."""
|
||||
# HA will convert to degrees F if needed
|
||||
unit_map = {
|
||||
self.gateway.const.SetReq.V_TEMP: TEMP_CELCIUS,
|
||||
self.gateway.const.SetReq.V_HUM: '%',
|
||||
self.gateway.const.SetReq.V_DIMMER: '%',
|
||||
self.gateway.const.SetReq.V_LIGHT_LEVEL: '%',
|
||||
self.gateway.const.SetReq.V_WEIGHT: 'kg',
|
||||
self.gateway.const.SetReq.V_DISTANCE: 'm',
|
||||
self.gateway.const.SetReq.V_IMPEDANCE: 'ohm',
|
||||
self.gateway.const.SetReq.V_WATT: 'W',
|
||||
self.gateway.const.SetReq.V_KWH: 'kWh',
|
||||
self.gateway.const.SetReq.V_FLOW: 'm',
|
||||
self.gateway.const.SetReq.V_VOLUME: 'm3',
|
||||
self.gateway.const.SetReq.V_VOLTAGE: 'V',
|
||||
self.gateway.const.SetReq.V_CURRENT: 'A',
|
||||
}
|
||||
unit_map_v15 = {
|
||||
self.gateway.const.SetReq.V_PERCENTAGE: '%',
|
||||
}
|
||||
if float(self.gateway.version) >= 1.5:
|
||||
if self.gateway.const.SetReq.V_UNIT_PREFIX in self._values:
|
||||
return self._values[
|
||||
self.gateway.const.SetReq.V_UNIT_PREFIX]
|
||||
unit_map.update(unit_map_v15)
|
||||
return unit_map.get(self.value_type)
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return device specific state attributes."""
|
||||
device_attr = {}
|
||||
for value_type, value in self._values.items():
|
||||
if value_type != self.value_type:
|
||||
device_attr[self.gateway.const.SetReq(value_type).name] = value
|
||||
return device_attr
|
||||
|
||||
@property
|
||||
def state_attributes(self):
|
||||
""" Returns the state attributes. """
|
||||
return {
|
||||
ATTR_NODE_ID: self.node_id,
|
||||
ATTR_CHILD_ID: self.child_id,
|
||||
"""Return the state attributes."""
|
||||
data = {
|
||||
mysensors.ATTR_PORT: self.gateway.port,
|
||||
mysensors.ATTR_NODE_ID: self.node_id,
|
||||
mysensors.ATTR_CHILD_ID: self.child_id,
|
||||
ATTR_BATTERY_LEVEL: self.battery_level,
|
||||
}
|
||||
|
||||
def update_sensor(self, value, battery_level):
|
||||
""" Update a sensor with the latest value from the controller. """
|
||||
_LOGGER.info("%s value = %s", self._name, value)
|
||||
if self.value_type == self.const.SetReq.V_TRIPPED or \
|
||||
self.value_type == self.const.SetReq.V_ARMED:
|
||||
self._value = STATE_ON if int(value) == 1 else STATE_OFF
|
||||
else:
|
||||
self._value = value
|
||||
self.battery_level = battery_level
|
||||
self.update_ha_state()
|
||||
device_attr = self.device_state_attributes
|
||||
|
||||
if device_attr is not None:
|
||||
data.update(device_attr)
|
||||
|
||||
return data
|
||||
|
||||
def update(self):
|
||||
"""Update the controller with the latest values from a sensor."""
|
||||
node = self.gateway.sensors[self.node_id]
|
||||
child = node.children[self.child_id]
|
||||
for value_type, value in child.values.items():
|
||||
_LOGGER.info(
|
||||
"%s: value_type %s, value = %s", self._name, value_type, value)
|
||||
if value_type == self.gateway.const.SetReq.V_TRIPPED:
|
||||
self._values[value_type] = STATE_ON if int(
|
||||
value) == 1 else STATE_OFF
|
||||
else:
|
||||
self._values[value_type] = value
|
||||
|
||||
self.battery_level = node.battery_level
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
"""
|
||||
homeassistant.components.sensor.nest
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Support for Nest Thermostat Sensors.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/sensor.nest/
|
||||
"""
|
||||
import logging
|
||||
import socket
|
||||
import homeassistant.components.nest as nest
|
||||
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.const import TEMP_CELCIUS
|
||||
|
||||
DEPENDENCIES = ['nest']
|
||||
SENSOR_TYPES = ['humidity',
|
||||
'mode',
|
||||
'last_ip',
|
||||
'local_ip',
|
||||
'last_connection',
|
||||
'battery_level']
|
||||
|
||||
SENSOR_UNITS = {'humidity': '%', 'battery_level': '%'}
|
||||
|
||||
SENSOR_TEMP_TYPES = ['temperature',
|
||||
'target',
|
||||
'away_temperature[0]',
|
||||
'away_temperature[1]']
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Setup Nest Sensor. """
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
try:
|
||||
for structure in nest.NEST.structures:
|
||||
for device in structure.devices:
|
||||
for variable in config['monitored_conditions']:
|
||||
if variable in SENSOR_TYPES:
|
||||
add_devices([NestBasicSensor(structure,
|
||||
device,
|
||||
variable)])
|
||||
elif variable in SENSOR_TEMP_TYPES:
|
||||
add_devices([NestTempSensor(structure,
|
||||
device,
|
||||
variable)])
|
||||
else:
|
||||
logger.error('Nest sensor type: "%s" does not exist',
|
||||
variable)
|
||||
except socket.error:
|
||||
logger.error(
|
||||
"Connection error logging into the nest web service."
|
||||
)
|
||||
|
||||
|
||||
class NestSensor(Entity):
|
||||
""" Represents a Nest sensor. """
|
||||
|
||||
def __init__(self, structure, device, variable):
|
||||
self.structure = structure
|
||||
self.device = device
|
||||
self.variable = variable
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" Returns the name of the nest, if any. """
|
||||
|
||||
location = self.device.where
|
||||
name = self.device.name
|
||||
if location is None:
|
||||
return "{} {}".format(name, self.variable)
|
||||
else:
|
||||
if name == '':
|
||||
return "{} {}".format(location.capitalize(), self.variable)
|
||||
else:
|
||||
return "{}({}){}".format(location.capitalize(),
|
||||
name,
|
||||
self.variable)
|
||||
|
||||
|
||||
class NestBasicSensor(NestSensor):
|
||||
""" Represents a basic Nest sensor with state. """
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
""" Returns the state of the sensor. """
|
||||
return getattr(self.device, self.variable)
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
""" Unit the value is expressed in. """
|
||||
return SENSOR_UNITS.get(self.variable, None)
|
||||
|
||||
|
||||
class NestTempSensor(NestSensor):
|
||||
""" Represents a Nest Temperature sensor. """
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
""" Unit the value is expressed in. """
|
||||
return TEMP_CELCIUS
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
""" Returns the state of the sensor. """
|
||||
temp = getattr(self.device, self.variable)
|
||||
if temp is None:
|
||||
return None
|
||||
|
||||
return round(temp, 1)
|
||||
@@ -0,0 +1,158 @@
|
||||
"""
|
||||
homeassistant.components.sensor.netatmo
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
NetAtmo Weather Service service.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/sensor.netatmo/
|
||||
"""
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
from homeassistant.components.sensor import DOMAIN
|
||||
from homeassistant.const import (CONF_API_KEY, CONF_USERNAME, CONF_PASSWORD,
|
||||
TEMP_CELCIUS)
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers import validate_config
|
||||
from homeassistant.util import Throttle
|
||||
|
||||
REQUIREMENTS = [
|
||||
'https://github.com/HydrelioxGitHub/netatmo-api-python/archive/'
|
||||
'43ff238a0122b0939a0dc4e8836b6782913fb6e2.zip'
|
||||
'#lnetatmo==0.4.0']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SENSOR_TYPES = {
|
||||
'temperature': ['Temperature', TEMP_CELCIUS, 'mdi:thermometer'],
|
||||
'co2': ['CO2', 'ppm', 'mdi:cloud'],
|
||||
'pressure': ['Pressure', 'mbar', 'mdi:gauge'],
|
||||
'noise': ['Noise', 'dB', 'mdi:volume-high'],
|
||||
'humidity': ['Humidity', '%', 'mdi:water-percent']
|
||||
}
|
||||
|
||||
CONF_SECRET_KEY = 'secret_key'
|
||||
ATTR_MODULE = 'modules'
|
||||
|
||||
# Return cached results if last scan was less then this time ago
|
||||
# NetAtmo Data is uploaded to server every 10mn
|
||||
# so this time should not be under
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=600)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Get the NetAtmo sensor. """
|
||||
|
||||
if not validate_config({DOMAIN: config},
|
||||
{DOMAIN: [CONF_API_KEY,
|
||||
CONF_USERNAME,
|
||||
CONF_PASSWORD,
|
||||
CONF_SECRET_KEY]},
|
||||
_LOGGER):
|
||||
return None
|
||||
|
||||
import lnetatmo
|
||||
|
||||
authorization = lnetatmo.ClientAuth(config.get(CONF_API_KEY, None),
|
||||
config.get(CONF_SECRET_KEY, None),
|
||||
config.get(CONF_USERNAME, None),
|
||||
config.get(CONF_PASSWORD, None))
|
||||
|
||||
if not authorization:
|
||||
_LOGGER.error(
|
||||
"Connection error "
|
||||
"Please check your settings for NatAtmo API.")
|
||||
return False
|
||||
|
||||
data = NetAtmoData(authorization)
|
||||
|
||||
dev = []
|
||||
try:
|
||||
# Iterate each module
|
||||
for module_name, monitored_conditions in config[ATTR_MODULE].items():
|
||||
# Test if module exist """
|
||||
if module_name not in data.get_module_names():
|
||||
_LOGGER.error('Module name: "%s" not found', module_name)
|
||||
continue
|
||||
# Only create sensor for monitored """
|
||||
for variable in monitored_conditions:
|
||||
if variable not in SENSOR_TYPES:
|
||||
_LOGGER.error('Sensor type: "%s" does not exist', variable)
|
||||
else:
|
||||
dev.append(
|
||||
NetAtmoSensor(data, module_name, variable))
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
add_devices(dev)
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class NetAtmoSensor(Entity):
|
||||
""" Implements a NetAtmo sensor. """
|
||||
|
||||
def __init__(self, netatmo_data, module_name, sensor_type):
|
||||
self._name = "NetAtmo {} {}".format(module_name,
|
||||
SENSOR_TYPES[sensor_type][0])
|
||||
self.netatmo_data = netatmo_data
|
||||
self.module_name = module_name
|
||||
self.type = sensor_type
|
||||
self._state = None
|
||||
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
|
||||
self.update()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
return SENSOR_TYPES[self.type][2]
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
""" Returns the state of the device. """
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
""" Unit of measurement of this entity, if any. """
|
||||
return self._unit_of_measurement
|
||||
|
||||
# pylint: disable=too-many-branches
|
||||
def update(self):
|
||||
""" Gets the latest data from NetAtmo API and updates the states. """
|
||||
|
||||
self.netatmo_data.update()
|
||||
data = self.netatmo_data.data[self.module_name]
|
||||
|
||||
if self.type == 'temperature':
|
||||
self._state = round(data['Temperature'], 1)
|
||||
elif self.type == 'humidity':
|
||||
self._state = data['Humidity']
|
||||
elif self.type == 'noise':
|
||||
self._state = data['Noise']
|
||||
elif self.type == 'co2':
|
||||
self._state = data['CO2']
|
||||
elif self.type == 'pressure':
|
||||
self._state = round(data['Pressure'], 1)
|
||||
|
||||
|
||||
class NetAtmoData(object):
|
||||
""" Gets the latest data from NetAtmo. """
|
||||
|
||||
def __init__(self, auth):
|
||||
self.auth = auth
|
||||
self.data = None
|
||||
|
||||
def get_module_names(self):
|
||||
""" Return all module available on the API as a list. """
|
||||
self.update()
|
||||
return self.data.keys()
|
||||
|
||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||
def update(self):
|
||||
""" Call the NetAtmo API to update the data. """
|
||||
import lnetatmo
|
||||
# Gets the latest data from NetAtmo. """
|
||||
dev_list = lnetatmo.DeviceList(self.auth)
|
||||
self.data = dev_list.lastData(exclude=3600)
|
||||
@@ -0,0 +1,100 @@
|
||||
"""
|
||||
homeassistant.components.sensor.onewire
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Support for DS18B20 One Wire Sensors.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/sensor.onewire/
|
||||
"""
|
||||
from glob import glob
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
from homeassistant.const import TEMP_CELCIUS, STATE_UNKNOWN
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
BASE_DIR = '/sys/bus/w1/devices/'
|
||||
DEVICE_FOLDERS = glob(os.path.join(BASE_DIR, '28*'))
|
||||
SENSOR_IDS = []
|
||||
DEVICE_FILES = []
|
||||
for device_folder in DEVICE_FOLDERS:
|
||||
SENSOR_IDS.append(os.path.split(device_folder)[1])
|
||||
DEVICE_FILES.append(os.path.join(device_folder, 'w1_slave'))
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Sets up the one wire Sensors. """
|
||||
|
||||
if DEVICE_FILES == []:
|
||||
_LOGGER.error('No onewire sensor found.')
|
||||
_LOGGER.error('Check if dtoverlay=w1-gpio,gpiopin=4.')
|
||||
_LOGGER.error('is in your /boot/config.txt and')
|
||||
_LOGGER.error('the correct gpiopin number is set.')
|
||||
return
|
||||
|
||||
devs = []
|
||||
names = SENSOR_IDS
|
||||
|
||||
for key in config.keys():
|
||||
if key == "names":
|
||||
# only one name given
|
||||
if isinstance(config['names'], str):
|
||||
names = [config['names']]
|
||||
# map names and sensors in given order
|
||||
elif isinstance(config['names'], list):
|
||||
names = config['names']
|
||||
# map names to ids.
|
||||
elif isinstance(config['names'], dict):
|
||||
names = []
|
||||
for sensor_id in SENSOR_IDS:
|
||||
names.append(config['names'].get(sensor_id, sensor_id))
|
||||
for device_file, name in zip(DEVICE_FILES, names):
|
||||
devs.append(OneWire(name, device_file))
|
||||
add_devices(devs)
|
||||
|
||||
|
||||
class OneWire(Entity):
|
||||
""" An One wire Sensor. """
|
||||
|
||||
def __init__(self, name, device_file):
|
||||
self._name = name
|
||||
self._device_file = device_file
|
||||
self._state = STATE_UNKNOWN
|
||||
self.update()
|
||||
|
||||
def _read_temp_raw(self):
|
||||
""" Read the temperature as it is returned by the sensor. """
|
||||
ds_device_file = open(self._device_file, 'r')
|
||||
lines = ds_device_file.readlines()
|
||||
ds_device_file.close()
|
||||
return lines
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" The name of the sensor. """
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
""" Returns the state of the device. """
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
""" Unit the value is expressed in. """
|
||||
return TEMP_CELCIUS
|
||||
|
||||
def update(self):
|
||||
""" Gets the latest data from the device. """
|
||||
lines = self._read_temp_raw()
|
||||
while lines[0].strip()[-3:] != 'YES':
|
||||
time.sleep(0.2)
|
||||
lines = self._read_temp_raw()
|
||||
equals_pos = lines[1].find('t=')
|
||||
if equals_pos != -1:
|
||||
temp_string = lines[1][equals_pos+2:]
|
||||
temp = float(temp_string) / 1000.0
|
||||
self._state = temp
|
||||
@@ -13,14 +13,14 @@ from homeassistant.util import Throttle
|
||||
from homeassistant.const import (CONF_API_KEY, TEMP_CELCIUS, TEMP_FAHRENHEIT)
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
REQUIREMENTS = ['pyowm==2.2.1']
|
||||
REQUIREMENTS = ['pyowm==2.3.0']
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
SENSOR_TYPES = {
|
||||
'weather': ['Condition', ''],
|
||||
'temperature': ['Temperature', ''],
|
||||
'weather': ['Condition', None],
|
||||
'temperature': ['Temperature', None],
|
||||
'wind_speed': ['Wind speed', 'm/s'],
|
||||
'humidity': ['Humidity', '%'],
|
||||
'pressure': ['Pressure', 'hPa'],
|
||||
'pressure': ['Pressure', 'mbar'],
|
||||
'clouds': ['Cloud coverage', '%'],
|
||||
'rain': ['Rain', 'mm'],
|
||||
'snow': ['Snow', 'mm']
|
||||
@@ -37,15 +37,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
_LOGGER.error("Latitude or longitude not set in Home Assistant config")
|
||||
return False
|
||||
|
||||
try:
|
||||
from pyowm import OWM
|
||||
|
||||
except ImportError:
|
||||
_LOGGER.exception(
|
||||
"Unable to import pyowm. "
|
||||
"Did you maybe not install the 'PyOWM' package?")
|
||||
|
||||
return False
|
||||
from pyowm import OWM
|
||||
|
||||
SENSOR_TYPES['temperature'][1] = hass.config.temperature_unit
|
||||
unit = hass.config.temperature_unit
|
||||
@@ -71,7 +63,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
pass
|
||||
|
||||
if forecast == 1:
|
||||
SENSOR_TYPES['forecast'] = ['Forecast', '']
|
||||
SENSOR_TYPES['forecast'] = ['Forecast', None]
|
||||
dev.append(OpenWeatherMapSensor(data, 'forecast', unit))
|
||||
|
||||
add_devices(dev)
|
||||
@@ -165,6 +157,10 @@ class WeatherData(object):
|
||||
def update(self):
|
||||
""" Gets the latest data from OpenWeatherMap. """
|
||||
obs = self.owm.weather_at_coords(self.latitude, self.longitude)
|
||||
if obs is None:
|
||||
_LOGGER.warning('Failed to fetch data from OWM')
|
||||
return
|
||||
|
||||
self.data = obs.get_weather()
|
||||
|
||||
if self.forecast == 1:
|
||||
|
||||
@@ -10,7 +10,7 @@ from datetime import timedelta
|
||||
import logging
|
||||
import requests
|
||||
|
||||
from homeassistant.const import CONF_VALUE_TEMPLATE
|
||||
from homeassistant.const import (CONF_VALUE_TEMPLATE, STATE_UNKNOWN)
|
||||
from homeassistant.util import template, Throttle
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
@@ -26,48 +26,21 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
|
||||
# pylint: disable=unused-variable
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Get the REST sensor. """
|
||||
|
||||
use_get = False
|
||||
use_post = False
|
||||
|
||||
resource = config.get('resource', None)
|
||||
method = config.get('method', DEFAULT_METHOD)
|
||||
payload = config.get('payload', None)
|
||||
verify_ssl = config.get('verify_ssl', True)
|
||||
|
||||
if method == 'GET':
|
||||
use_get = True
|
||||
elif method == 'POST':
|
||||
use_post = True
|
||||
rest = RestData(method, resource, payload, verify_ssl)
|
||||
rest.update()
|
||||
|
||||
try:
|
||||
if use_get:
|
||||
response = requests.get(resource, timeout=10, verify=verify_ssl)
|
||||
elif use_post:
|
||||
response = requests.post(resource, data=payload, timeout=10,
|
||||
verify=verify_ssl)
|
||||
if not response.ok:
|
||||
_LOGGER.error('Response status is "%s"', response.status_code)
|
||||
return False
|
||||
except requests.exceptions.MissingSchema:
|
||||
_LOGGER.error('Missing resource or schema in configuration. '
|
||||
'Add http:// to your URL.')
|
||||
return False
|
||||
except requests.exceptions.ConnectionError:
|
||||
_LOGGER.error('No route to resource/endpoint. '
|
||||
'Please check the URL in the configuration file.')
|
||||
if rest.data is None:
|
||||
_LOGGER.error('Unable to fetch Rest data')
|
||||
return False
|
||||
|
||||
if use_get:
|
||||
rest = RestDataGet(resource, verify_ssl)
|
||||
elif use_post:
|
||||
rest = RestDataPost(resource, payload, verify_ssl)
|
||||
|
||||
add_devices([RestSensor(hass,
|
||||
rest,
|
||||
config.get('name', DEFAULT_NAME),
|
||||
config.get('unit_of_measurement'),
|
||||
config.get(CONF_VALUE_TEMPLATE))])
|
||||
add_devices([RestSensor(
|
||||
hass, rest, config.get('name', DEFAULT_NAME),
|
||||
config.get('unit_of_measurement'), config.get(CONF_VALUE_TEMPLATE))])
|
||||
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
@@ -78,7 +51,7 @@ class RestSensor(Entity):
|
||||
self._hass = hass
|
||||
self.rest = rest
|
||||
self._name = name
|
||||
self._state = 'n/a'
|
||||
self._state = STATE_UNKNOWN
|
||||
self._unit_of_measurement = unit_of_measurement
|
||||
self._value_template = value_template
|
||||
self.update()
|
||||
@@ -103,57 +76,33 @@ class RestSensor(Entity):
|
||||
self.rest.update()
|
||||
value = self.rest.data
|
||||
|
||||
if 'error' in value:
|
||||
self._state = value['error']
|
||||
else:
|
||||
if self._value_template is not None:
|
||||
value = template.render_with_possible_json_value(
|
||||
self._hass, self._value_template, value, 'N/A')
|
||||
self._state = value
|
||||
if value is None:
|
||||
value = STATE_UNKNOWN
|
||||
elif self._value_template is not None:
|
||||
value = template.render_with_possible_json_value(
|
||||
self._hass, self._value_template, value, STATE_UNKNOWN)
|
||||
|
||||
self._state = value
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class RestDataGet(object):
|
||||
""" Class for handling the data retrieval with GET method. """
|
||||
class RestData(object):
|
||||
"""Class for handling the data retrieval."""
|
||||
|
||||
def __init__(self, resource, verify_ssl):
|
||||
self._resource = resource
|
||||
def __init__(self, method, resource, data, verify_ssl):
|
||||
self._request = requests.Request(method, resource, data=data).prepare()
|
||||
self._verify_ssl = verify_ssl
|
||||
self.data = dict()
|
||||
self.data = None
|
||||
|
||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||
def update(self):
|
||||
""" Gets the latest data from REST service with GET method. """
|
||||
try:
|
||||
response = requests.get(self._resource, timeout=10,
|
||||
verify=self._verify_ssl)
|
||||
if 'error' in self.data:
|
||||
del self.data['error']
|
||||
with requests.Session() as sess:
|
||||
response = sess.send(self._request, timeout=10,
|
||||
verify=self._verify_ssl)
|
||||
|
||||
self.data = response.text
|
||||
except requests.exceptions.ConnectionError:
|
||||
_LOGGER.error("No route to resource/endpoint.")
|
||||
self.data['error'] = 'N/A'
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class RestDataPost(object):
|
||||
""" Class for handling the data retrieval with POST method. """
|
||||
|
||||
def __init__(self, resource, payload, verify_ssl):
|
||||
self._resource = resource
|
||||
self._payload = payload
|
||||
self._verify_ssl = verify_ssl
|
||||
self.data = dict()
|
||||
|
||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||
def update(self):
|
||||
""" Gets the latest data from REST service with POST method. """
|
||||
try:
|
||||
response = requests.post(self._resource, data=self._payload,
|
||||
timeout=10, verify=self._verify_ssl)
|
||||
if 'error' in self.data:
|
||||
del self.data['error']
|
||||
self.data = response.text
|
||||
except requests.exceptions.ConnectionError:
|
||||
_LOGGER.error("No route to resource/endpoint.")
|
||||
self.data['error'] = 'N/A'
|
||||
except requests.exceptions.RequestException:
|
||||
_LOGGER.error("Error fetching data: %s", self._request)
|
||||
self.data = None
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user