Putting the DB on a Diet and then watching it for growth with a sensor!
This commit is contained in:
parent
398d978487
commit
fd49bd12bc
|
@ -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 = "/Users/hass/.homeassistant/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
|
|
@ -8,21 +8,56 @@ exclude:
|
|||
domains:
|
||||
- updater
|
||||
- automation
|
||||
- device_tracker
|
||||
- group
|
||||
- scene
|
||||
- script
|
||||
entities:
|
||||
- group.motion
|
||||
- group.doors
|
||||
- binary_sensor.bedroom_motion
|
||||
- binary_sensor.clock_motion
|
||||
- sensor.bitcoin
|
||||
- sensor.carlo_6s_battery_state
|
||||
- sensor.clock_am_pm
|
||||
- sensor.clock_date
|
||||
- sensor.clock_day
|
||||
- sensor.clock_stacey_alarm_time
|
||||
- sensor.clock_time
|
||||
- sensor.dark_sky_cloud_coverage
|
||||
- sensor.dark_sky_daily_max_precip_intensity
|
||||
- sensor.dark_sky_humidity
|
||||
- sensor.dark_sky_minutely_summary
|
||||
- sensor.dark_sky_precip_intensity
|
||||
- sensor.dark_sky_temperature
|
||||
- sensor.dark_sky_uv_index
|
||||
- sensor.dark_sky_wind_speed
|
||||
- sensor.date
|
||||
- sensor.epson_ink_level_black
|
||||
- sensor.epson_ink_level_cyan
|
||||
- sensor.epson_ink_level_magenta
|
||||
- sensor.epson_ink_level_photo_black
|
||||
- sensor.epson_ink_level_yellow
|
||||
- sensor.external_ip
|
||||
- sensor.floorplan_date
|
||||
- sensor.floorplan_time
|
||||
- sensor.ha_uptime
|
||||
- sensor.large_garage_reflection_rate
|
||||
- sensor.large_garage_time_in_state
|
||||
- sensor.large_garage_wifi_signal_strength
|
||||
- sensor.last_message
|
||||
- sensor.low_battery
|
||||
- sensor.network
|
||||
- sensor.network_detail
|
||||
- sensor.pihole_ads_blocked_today
|
||||
- sensor.pihole_ads_percentage_blocked_today
|
||||
- sensor.pihole_dns_queries_today
|
||||
- sensor.pihole_dns_unique_clients
|
||||
- sensor.since_last_boot
|
||||
- sensor.since_last_boot_templated
|
||||
- sensor.small_garage_reflection_rate
|
||||
- sensor.small_garage_time_in_state
|
||||
- sensor.small_garage_wifi_signal_strength
|
||||
- sensor.staceys_iphone_battery_level
|
||||
- sensor.tesla
|
||||
- sensor.time
|
||||
- sensor.weather_apparent_temperature
|
||||
- sensor.weather_humidity
|
||||
- sensor.weather_icon
|
||||
- sensor.weather_precip_intensity
|
||||
- sensor.weather_precip_probability
|
||||
- sensor.weather_summary
|
||||
- sensor.weather_temperature
|
||||
- sensor.weather_hourly_summary
|
||||
- sensor.weather_daily_summary
|
||||
- sensor.weather_wind_speed
|
||||
- sun.sun
|
||||
- zone.home
|
||||
|
|
Loading…
Reference in New Issue