updates to 0.115.5

This commit is contained in:
Mahasri Kalavala
2020-09-29 22:36:02 -04:00
parent 86d1f32caf
commit b21706d3cd
14 changed files with 402 additions and 775 deletions

View File

@@ -18,9 +18,9 @@ from homeassistant.const import (
CONF_SENSORS,
CONF_SSL,
CONTENT_TYPE_JSON,
PERCENTAGE,
TEMP_CELSIUS,
TIME_SECONDS,
UNIT_PERCENTAGE,
)
from homeassistant.helpers import discovery
import homeassistant.helpers.config_validation as cv
@@ -76,7 +76,7 @@ SENSOR_TYPES = {
"job",
"progress",
"completion",
UNIT_PERCENTAGE,
PERCENTAGE,
"mdi:file-percent",
],
"Time Remaining": [
@@ -146,9 +146,10 @@ def setup(hass, config):
for printer in config[DOMAIN]:
name = printer[CONF_NAME]
ssl = "s" if printer[CONF_SSL] else ""
base_url = "http{}://{}:{}{}api/".format(
ssl, printer[CONF_HOST], printer[CONF_PORT], printer[CONF_PATH]
protocol = "https" if printer[CONF_SSL] else "http"
base_url = (
f"{protocol}://{printer[CONF_HOST]}:{printer[CONF_PORT]}"
f"{printer[CONF_PATH]}api/"
)
api_key = printer[CONF_API_KEY]
number_of_tools = printer[CONF_NUMBER_OF_TOOLS]
@@ -230,7 +231,6 @@ class OctoPrintAPI:
return self.printer_last_reading[0]
url = self.api_url + endpoint
try:
response = requests.get(url, headers=self.headers, timeout=9)
response.raise_for_status()

View File

@@ -3,7 +3,7 @@ import logging
import requests
from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.components.binary_sensor import BinarySensorEntity
from . import BINARY_SENSOR_TYPES, DOMAIN as COMPONENT_DOMAIN
@@ -36,7 +36,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities(devices, True)
class OctoPrintBinarySensor(BinarySensorDevice):
class OctoPrintBinarySensor(BinarySensorEntity):
"""Representation an OctoPrint binary sensor."""
def __init__(

View File

@@ -3,7 +3,7 @@ import logging
import requests
from homeassistant.const import TEMP_CELSIUS, UNIT_PERCENTAGE
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS
from homeassistant.helpers.entity import Entity
from . import DOMAIN as COMPONENT_DOMAIN, SENSOR_TYPES
@@ -32,7 +32,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
"If you do not want to have your printer on <br />"
" at all times, and you would like to monitor <br /> "
"temperatures, please add <br />"
"bed and/or number&#95of&#95tools to your configuration <br />"
"bed and/or number&#95;of&#95;tools to your configuration <br />"
"and restart.",
title=NOTIFICATION_TITLE,
notification_id=NOTIFICATION_ID,
@@ -91,7 +91,7 @@ class OctoPrintSensor(Entity):
if tool is None:
self._name = f"{sensor_name} {condition}"
else:
self._name = "{} {} {} {}".format(sensor_name, condition, tool, "temp")
self._name = f"{sensor_name} {condition} {tool} temp"
self.sensor_type = sensor_type
self.api = api
self._state = None
@@ -111,7 +111,7 @@ class OctoPrintSensor(Entity):
def state(self):
"""Return the state of the sensor."""
sensor_unit = self.unit_of_measurement
if sensor_unit in (TEMP_CELSIUS, UNIT_PERCENTAGE):
if sensor_unit in (TEMP_CELSIUS, PERCENTAGE):
# API sometimes returns null and not 0
if self._state is None:
self._state = 0