You can find the entire repo here.

This commit is contained in:
ccostan
2018-02-28 19:43:00 -05:00
parent ddcf503781
commit 40f8fd2edc
263 changed files with 0 additions and 194 deletions

View File

@@ -0,0 +1,97 @@
"""
Binary sensor support for the Skybell HD Doorbell.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/binary_sensor.skybell/
"""
from datetime import timedelta
import logging
import voluptuous as vol
from homeassistant.components.binary_sensor import (
BinarySensorDevice, PLATFORM_SCHEMA)
from homeassistant.components.skybell import (
DEFAULT_ENTITY_NAMESPACE, DOMAIN as SKYBELL_DOMAIN, SkybellDevice)
from homeassistant.const import (
CONF_ENTITY_NAMESPACE, CONF_MONITORED_CONDITIONS)
import homeassistant.helpers.config_validation as cv
DEPENDENCIES = ['skybell']
_LOGGER = logging.getLogger(__name__)
SCAN_INTERVAL = timedelta(seconds=5)
# Sensor types: Name, device_class, event
SENSOR_TYPES = {
'button': ['Button', 'occupancy', 'device:sensor:button'],
'motion': ['Motion', 'motion', 'device:sensor:motion'],
}
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_ENTITY_NAMESPACE, default=DEFAULT_ENTITY_NAMESPACE):
cv.string,
vol.Required(CONF_MONITORED_CONDITIONS, default=[]):
vol.All(cv.ensure_list, [vol.In(SENSOR_TYPES)]),
})
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the platform for a Skybell device."""
skybell = hass.data.get(SKYBELL_DOMAIN)
sensors = []
for sensor_type in config.get(CONF_MONITORED_CONDITIONS):
for device in skybell.get_devices():
sensors.append(SkybellBinarySensor(device, sensor_type))
add_devices(sensors, True)
class SkybellBinarySensor(SkybellDevice, BinarySensorDevice):
"""A binary sensor implementation for Skybell devices."""
def __init__(self, device, sensor_type):
"""Initialize a binary sensor for a Skybell device."""
super().__init__(device)
self._sensor_type = sensor_type
self._name = "{0} {1}".format(self._device.name,
SENSOR_TYPES[self._sensor_type][0])
self._device_class = SENSOR_TYPES[self._sensor_type][1]
self._event = {}
self._state = None
@property
def name(self):
"""Return the name of the sensor."""
return self._name
@property
def is_on(self):
"""Return True if the binary sensor is on."""
return self._state
@property
def device_class(self):
"""Return the class of the binary sensor."""
return self._device_class
@property
def device_state_attributes(self):
"""Return the state attributes."""
attrs = super().device_state_attributes
# attrs['event_date'] = self._event.get('createdAt')
return attrs
def update(self):
"""Get the latest data and updates the state."""
super().update()
event = self._device.latest(SENSOR_TYPES[self._sensor_type][2])
self._state = bool(event and event.get('id') != self._event.get('id'))
self._event = event

View File

@@ -0,0 +1,12 @@
# [![Build Status](https://travis-ci.org/CCOSTAN/Home-AssistantConfig.svg?branch=master)](https://travis-ci.org/CCOSTAN/Home-AssistantConfig) Home-Assistant Config by [@ccostan](http://www.twitter.com/ccostan)
[Home Assistant](https://home-assistant.io/) configuration files (YAMLs)
Be sure to :star: my repo so you can keep up to date on the daily progress!
This is a Custom Component by pkozul to allow me to use my Floorplan installation as a Media Player. This allows me to send all TTS and home notifications to the Fire Tablets I use with Floorplan.
#Still have questions on my Config?
Follow me on twitter : [@CCostan](https://twitter.com/ccostan)
You can also vist my [Blog](http://www.vmwareinfo.com/search/label/iot) for all of my [Home Automation Posts](http://www.vmwareinfo.com/search/label/iot).

View File

@@ -0,0 +1,329 @@
"""
Provide functionality to interact with Cast devices on the network.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/media_player.cast/
"""
# pylint: disable=import-error
import logging
import voluptuous as vol
from homeassistant.components.media_player import (
MEDIA_TYPE_MUSIC, MEDIA_TYPE_TVSHOW, MEDIA_TYPE_VIDEO, SUPPORT_NEXT_TRACK,
SUPPORT_PAUSE, SUPPORT_PLAY_MEDIA, SUPPORT_PREVIOUS_TRACK,
SUPPORT_TURN_OFF, SUPPORT_TURN_ON, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET,
SUPPORT_STOP, SUPPORT_PLAY, MediaPlayerDevice, PLATFORM_SCHEMA)
from homeassistant.const import (
CONF_HOST, STATE_IDLE, STATE_OFF, STATE_PAUSED, STATE_PLAYING,
STATE_UNKNOWN)
import homeassistant.helpers.config_validation as cv
import homeassistant.util.dt as dt_util
# Do not upgrade to 1.0.2, it breaks a bunch of stuff
# https://github.com/home-assistant/home-assistant/issues/10926
REQUIREMENTS = ['pychromecast==1.0.3']
_LOGGER = logging.getLogger(__name__)
CONF_IGNORE_CEC = 'ignore_cec'
CAST_SPLASH = 'https://home-assistant.io/images/cast/splash.png'
DEFAULT_PORT = 8009
SUPPORT_CAST = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
SUPPORT_TURN_ON | SUPPORT_TURN_OFF | SUPPORT_PREVIOUS_TRACK | \
SUPPORT_NEXT_TRACK | SUPPORT_PLAY_MEDIA | SUPPORT_STOP | SUPPORT_PLAY
KNOWN_HOSTS_KEY = 'cast_known_hosts'
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_HOST): cv.string,
vol.Optional(CONF_IGNORE_CEC): [cv.string],
})
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the cast platform."""
import pychromecast
# Import CEC IGNORE attributes
pychromecast.IGNORE_CEC += config.get(CONF_IGNORE_CEC, [])
known_hosts = hass.data.get(KNOWN_HOSTS_KEY)
if known_hosts is None:
known_hosts = hass.data[KNOWN_HOSTS_KEY] = []
if discovery_info:
host = (discovery_info.get('host'), discovery_info.get('port'))
if host in known_hosts:
return
hosts = [host]
elif CONF_HOST in config:
host = (config.get(CONF_HOST), DEFAULT_PORT)
if host in known_hosts:
return
hosts = [host]
else:
hosts = [tuple(dev[:2]) for dev in pychromecast.discover_chromecasts()
if tuple(dev[:2]) not in known_hosts]
casts = []
# get_chromecasts() returns Chromecast objects with the correct friendly
# name for grouped devices
all_chromecasts = pychromecast.get_chromecasts()
for host in hosts:
(_, port) = host
found = [device for device in all_chromecasts
if (device.host, device.port) == host]
if found:
try:
casts.append(CastDevice(found[0]))
known_hosts.append(host)
except pychromecast.ChromecastConnectionError:
pass
# do not add groups using pychromecast.Chromecast as it leads to names
# collision since pychromecast.Chromecast will get device name instead
# of group name
elif port == DEFAULT_PORT:
try:
# add the device anyway, get_chromecasts couldn't find it
casts.append(CastDevice(pychromecast.Chromecast(*host)))
known_hosts.append(host)
except pychromecast.ChromecastConnectionError:
pass
add_devices(casts)
class CastDevice(MediaPlayerDevice):
"""Representation of a Cast device on the network."""
def __init__(self, chromecast):
"""Initialize the Cast device."""
self.cast = chromecast
self.cast.socket_client.receiver_controller.register_status_listener(
self)
self.cast.socket_client.media_controller.register_status_listener(self)
self.cast_status = self.cast.status
self.media_status = self.cast.media_controller.status
self.media_status_received = None
@property
def should_poll(self):
"""No polling needed."""
return False
@property
def name(self):
"""Return the name of the device."""
return self.cast.device.friendly_name
# MediaPlayerDevice properties and methods
@property
def state(self):
"""Return the state of the player."""
if self.media_status is None:
return STATE_UNKNOWN
elif self.media_status.player_is_playing:
return STATE_PLAYING
elif self.media_status.player_is_paused:
return STATE_PAUSED
elif self.media_status.player_is_idle:
return STATE_IDLE
elif self.cast.is_idle:
return STATE_OFF
return STATE_UNKNOWN
@property
def volume_level(self):
"""Volume level of the media player (0..1)."""
return self.cast_status.volume_level if self.cast_status else None
@property
def is_volume_muted(self):
"""Boolean if volume is currently muted."""
return self.cast_status.volume_muted if self.cast_status else None
@property
def media_content_id(self):
"""Content ID of current playing media."""
return self.media_status.content_id if self.media_status else None
@property
def media_content_type(self):
"""Content type of current playing media."""
if self.media_status is None:
return None
elif self.media_status.media_is_tvshow:
return MEDIA_TYPE_TVSHOW
elif self.media_status.media_is_movie:
return MEDIA_TYPE_VIDEO
elif self.media_status.media_is_musictrack:
return MEDIA_TYPE_MUSIC
return None
@property
def media_duration(self):
"""Duration of current playing media in seconds."""
return self.media_status.duration if self.media_status else None
@property
def media_image_url(self):
"""Image url of current playing media."""
if self.media_status is None:
return None
images = self.media_status.images
return images[0].url if images else None
@property
def media_title(self):
"""Title of current playing media."""
return self.media_status.title if self.media_status else None
@property
def media_artist(self):
"""Artist of current playing media (Music track only)."""
return self.media_status.artist if self.media_status else None
@property
def media_album(self):
"""Album of current playing media (Music track only)."""
return self.media_status.album_name if self.media_status else None
@property
def media_album_artist(self):
"""Album arist of current playing media (Music track only)."""
return self.media_status.album_artist if self.media_status else None
@property
def media_track(self):
"""Track number of current playing media (Music track only)."""
return self.media_status.track if self.media_status else None
@property
def media_series_title(self):
"""Return the title of the series of current playing media."""
return self.media_status.series_title if self.media_status else None
@property
def media_season(self):
"""Season of current playing media (TV Show only)."""
return self.media_status.season if self.media_status else None
@property
def media_episode(self):
"""Episode of current playing media (TV Show only)."""
return self.media_status.episode if self.media_status else None
@property
def app_id(self):
"""Return the ID of the current running app."""
return self.cast.app_id
@property
def app_name(self):
"""Name of the current running app."""
return self.cast.app_display_name
@property
def supported_features(self):
"""Flag media player features that are supported."""
return SUPPORT_CAST
@property
def media_position(self):
"""Position of current playing media in seconds."""
if self.media_status is None or \
not (self.media_status.player_is_playing or
self.media_status.player_is_paused or
self.media_status.player_is_idle):
return None
return self.media_status.current_time
@property
def media_position_updated_at(self):
"""When was the position of the current playing media valid.
Returns value from homeassistant.util.dt.utcnow().
"""
return self.media_status_received
def turn_on(self):
"""Turn on the ChromeCast."""
# The only way we can turn the Chromecast is on is by launching an app
if not self.cast.status or not self.cast.status.is_active_input:
import pychromecast
if self.cast.app_id:
self.cast.quit_app()
self.cast.play_media(
CAST_SPLASH, pychromecast.STREAM_TYPE_BUFFERED)
def turn_off(self):
"""Turn Chromecast off."""
self.cast.quit_app()
def mute_volume(self, mute):
"""Mute the volume."""
self.cast.set_volume_muted(mute)
def set_volume_level(self, volume):
"""Set volume level, range 0..1."""
self.cast.set_volume(volume)
def media_play(self):
"""Send play command."""
self.cast.media_controller.play()
def media_pause(self):
"""Send pause command."""
self.cast.media_controller.pause()
def media_stop(self):
"""Send stop command."""
self.cast.media_controller.stop()
def media_previous_track(self):
"""Send previous track command."""
self.cast.media_controller.rewind()
def media_next_track(self):
"""Send next track command."""
self.cast.media_controller.skip()
def media_seek(self, position):
"""Seek the media to a specific location."""
self.cast.media_controller.seek(position)
def play_media(self, media_type, media_id, **kwargs):
"""Play media from a URL."""
self.cast.media_controller.play_media(media_id, media_type)
# Implementation of chromecast status_listener methods
def new_cast_status(self, status):
"""Handle updates of the cast status."""
self.cast_status = status
self.schedule_update_ha_state()
def new_media_status(self, status):
"""Handle updates of the media status."""
self.media_status = status
self.media_status_received = dt_util.utcnow()
self.schedule_update_ha_state()

View File

@@ -0,0 +1,160 @@
"""
Support for Floorplan Speaker
"""
import voluptuous as vol
from homeassistant.components.media_player import (
ENTITY_ID_FORMAT,
SUPPORT_PLAY_MEDIA,
SUPPORT_VOLUME_SET,
PLATFORM_SCHEMA,
MediaPlayerDevice)
from homeassistant.const import (
CONF_NAME, STATE_IDLE, STATE_PLAYING)
from homeassistant.components import http
from homeassistant.components.http import HomeAssistantView
from homeassistant.helpers.entity import async_generate_entity_id
import homeassistant.helpers.config_validation as cv
import logging
import os
import re
import sys
import time
import asyncio
import json
DEFAULT_NAME = 'Floorplan Speaker'
DEFAULT_VOLUME = 1.0
SUPPORT_FLOORPLAN_SPEAKER = SUPPORT_PLAY_MEDIA | SUPPORT_VOLUME_SET
CONF_ADDRESS = 'address'
ATTR_ADDRESS = 'address'
ATTR_BATTERY_LEVEL = 'battery_level'
ATTR_SCREEN_BRIGHTNESS = 'screen_brightness'
ATTR_DEVICE_ID = 'device_id'
ATTR_SERIAL_NUMBER = 'serial_number'
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
})
_LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None):
name = config.get(CONF_NAME)
address = config.get(CONF_ADDRESS)
device = FloorplanSpeakerDevice(hass, name, address)
"""Set up an endpoint for the media player."""
hass.http.register_view(device)
add_devices([device])
return True
class FloorplanSpeakerDevice(MediaPlayerDevice, http.HomeAssistantView):
def __init__(self, hass, name, address):
self._hass = hass
self._name = name
self.entity_id = async_generate_entity_id(ENTITY_ID_FORMAT, name, hass=hass)
self._state = STATE_IDLE
self._media_content_id = None
self._address = address
self._volume = DEFAULT_VOLUME
self._battery_level = None
self._screen_brightness = None
self._device_id = None
self._serial_number = None
self.url = '/api/fully_kiosk/media_player/' + self.entity_id
_LOGGER.info('Setting endpoint: %s', self.url)
@asyncio.coroutine
def post(self, request):
body = yield from request.text()
try:
data = json.loads(body) if body else None
except ValueError:
return self.json_message('Event data should be valid JSON', HTTP_BAD_REQUEST)
if data is not None and not isinstance(data, dict):
return self.json_message('Event data should be a JSON object', HTTP_BAD_REQUEST)
data = json.loads(body) if body else None
_LOGGER.info("Received from Fully Kiosk: %s: %s", self.url, data)
self._state = data['state']
self._media_content_id = data['attributes']['media_content_id']
self._volume = data['attributes']['volume_level']
self._address = data['attributes'][ATTR_ADDRESS]
self._battery_level = data['attributes'][ATTR_BATTERY_LEVEL]
self._screen_brightness = data['attributes'][ATTR_SCREEN_BRIGHTNESS]
self._device_id = data['attributes'][ATTR_DEVICE_ID]
self._serial_number = data['attributes'][ATTR_SERIAL_NUMBER]
@property
def name(self):
return self._name
@property
def state(self):
return self._state
@property
def supported_features(self):
return SUPPORT_FLOORPLAN_SPEAKER
@property
def address(self):
return self._address
@property
def volume_level(self):
return self._volume
@property
def media_content_id(self):
return self._media_content_id
@property
def battery_level(self):
return self._battery_level
@property
def device_id(self):
return self._device_id
@property
def serial_number(self):
return self._serial_number
@property
def device_state_attributes(self):
return {
ATTR_ADDRESS: self._address,
ATTR_BATTERY_LEVEL: self._battery_level,
ATTR_SCREEN_BRIGHTNESS: self._screen_brightness,
ATTR_DEVICE_ID: self._device_id,
ATTR_SERIAL_NUMBER: self._serial_number,
}
def set_volume_level(self, volume):
self._volume = volume
def play_media(self, media_type, media_id, **kwargs):
_LOGGER.info('play_media: %s', media_id)
def media_play(self):
_LOGGER.info('media_play')
def media_pause(self):
_LOGGER.info('media_pause')
def media_stop(self):
_LOGGER.info('media_stop')

View File

@@ -0,0 +1,69 @@
"""
Sensor for checking the size of your HA database file.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.database
"""
import logging
import os
from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__)
PATH = "/config/home-assistant_v2.db"
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the database sensor."""
db = Database(PATH)
add_devices([db], True)
class Database(Entity):
"""Representation of the HA database."""
ICON = 'mdi:harddisk'
def __init__(self, path):
"""Initialize the data object."""
self._path = path # Need to check its a valid path
self._size = None
self._name = "Database_sensor"
self._attributes = {}
self._unit_of_measurement = 'MB'
self.update()
def update(self):
"""Get the size of the database."""
self._size = self.get_db_size(self._path)
def get_db_size(self, path):
statinfo = os.stat(path)
decimals = 2
db_size = round(statinfo.st_size/1e6, decimals)
return db_size
@property
def name(self):
"""Return the name of the sensor."""
return self._name
@property
def state(self):
"""Return the state of the sensor."""
return self._size
@property
def icon(self):
"""Icon to use in the frontend, if any."""
return self.ICON
@property
def device_state_attributes(self):
"""Attributes."""
return self._attributes
@property
def unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement

View File

@@ -0,0 +1,82 @@
"""
Sensor to check the status of a Minecraft server.
"""
import logging
from homeassistant.helpers.entity import Entity
ATTR_USERS = 'users_online'
ATTR_MAX = 'users_max'
ATTR_MOTD = 'MOTD'
ATTR_VERSION = 'Version'
ICON = 'mdi:minecraft'
REQUIREMENTS = ['mcstatus==2.1']
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Minecraft server platform."""
from mcstatus import MinecraftServer as mcserver
logger = logging.getLogger(__name__)
server = config.get('server')
name = config.get('name')
if server is None:
logger.error('No server specified')
return False
elif name is None:
logger.error('No name specified')
return False
add_devices([
MCServerSensor(server, name, mcserver)
])
class MCServerSensor(Entity):
"""A class for the Minecraft server."""
# pylint: disable=abstract-method
def __init__(self, server, name, mcserver):
"""Initialize the sensor."""
self._mcserver = mcserver
self._server = server
self._name = name
self.update()
@property
def name(self):
"""Return the name of the server."""
return self._name
@property
def state(self):
"""Return the state of the sensor."""
return self._state
# pylint: disable=no-member
def update(self):
"""Update device state."""
status = self._mcserver.lookup(self._server).status()
query = self._mcserver.lookup(self._server).query()
self._state = status.players.online
#self._max = str(status.players.max)
self._max = status.players.max
self._users = query.players.names
self._motd = query.motd
self._version = query.software.version
@property
def device_state_attributes(self):
"""Return the state attributes."""
return {
ATTR_USERS: self._users,
ATTR_MAX: self._max,
ATTR_MOTD: self._motd,
ATTR_VERSION: self._version
}
@property
def icon(self):
"""Return the icon to use in the frontend."""
return ICON