From a22342b138eefb635192f0591155d210be1a509c Mon Sep 17 00:00:00 2001 From: ccostan Date: Fri, 3 Aug 2018 13:34:52 -0400 Subject: [PATCH] Migrating #408 over from Custom component. --- config/custom_components/sensor/database.py | 69 --------------------- config/packages/processmonitor.yaml | 4 +- 2 files changed, 3 insertions(+), 70 deletions(-) delete mode 100755 config/custom_components/sensor/database.py diff --git a/config/custom_components/sensor/database.py b/config/custom_components/sensor/database.py deleted file mode 100755 index aeba1fd2..00000000 --- a/config/custom_components/sensor/database.py +++ /dev/null @@ -1,69 +0,0 @@ -""" -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 \ No newline at end of file diff --git a/config/packages/processmonitor.yaml b/config/packages/processmonitor.yaml index 0f8589a2..eeb21b66 100755 --- a/config/packages/processmonitor.yaml +++ b/config/packages/processmonitor.yaml @@ -17,7 +17,9 @@ sensor: - type: since_last_boot - type: disk_use_percent arg: / - - platform: database + - platform: filesize + file_paths: + - /config/home-assistant_v2.db #------------------------------------------- ############################################################################## ### Automations - Detect when things are not right. Like any Good Watchdog.