1 """Support for Vultr."""
3 from datetime
import timedelta
6 import voluptuous
as vol
7 from vultr
import Vultr
as VultrAPI
16 _LOGGER = logging.getLogger(__name__)
18 ATTR_AUTO_BACKUPS =
"auto_backups"
19 ATTR_ALLOWED_BANDWIDTH =
"allowed_bandwidth_gb"
20 ATTR_COST_PER_MONTH =
"cost_per_month"
21 ATTR_CURRENT_BANDWIDTH_USED =
"current_bandwidth_gb"
22 ATTR_CREATED_AT =
"created_at"
24 ATTR_SUBSCRIPTION_ID =
"subid"
25 ATTR_SUBSCRIPTION_NAME =
"label"
26 ATTR_IPV4_ADDRESS =
"ipv4_address"
27 ATTR_IPV6_ADDRESS =
"ipv6_address"
28 ATTR_MEMORY =
"memory"
30 ATTR_PENDING_CHARGES =
"pending_charges"
31 ATTR_REGION =
"region"
34 CONF_SUBSCRIPTION =
"subscription"
36 DATA_VULTR =
"data_vultr"
39 NOTIFICATION_ID =
"vultr_notification"
40 NOTIFICATION_TITLE =
"Vultr Setup"
42 VULTR_PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR, Platform.SWITCH]
46 CONFIG_SCHEMA = vol.Schema(
47 {DOMAIN: vol.Schema({vol.Required(CONF_API_KEY): cv.string})}, extra=vol.ALLOW_EXTRA
51 def setup(hass: HomeAssistant, config: ConfigType) -> bool:
52 """Set up the Vultr component."""
53 api_key = config[DOMAIN].
get(CONF_API_KEY)
55 vultr =
Vultr(api_key)
59 except RuntimeError
as ex:
60 _LOGGER.error(
"Failed to make update API request because: %s", ex)
61 persistent_notification.create(
64 title=NOTIFICATION_TITLE,
65 notification_id=NOTIFICATION_ID,
69 hass.data[DATA_VULTR] = vultr
74 """Handle all communication with the Vultr API."""
77 """Initialize the Vultr connection."""
83 @Throttle(MIN_TIME_BETWEEN_UPDATES)
85 """Use the data from Vultr API."""
86 self.
datadata = self.
apiapi.server_list()
89 """Use the data from Vultr API."""
90 self.
datadata = self.
apiapi.server_list()
92 def halt(self, subscription):
93 """Halt a subscription (hard power off)."""
94 self.
apiapi.server_halt(subscription)
98 """Start a subscription."""
99 self.
apiapi.server_start(subscription)
def start(self, subscription)
def halt(self, subscription)
def __init__(self, api_key)
web.Response get(self, web.Request request, str config_key)
bool setup(HomeAssistant hass, ConfigType config)