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,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