I am getting an error when I try to set an input_slider to 0. The input_slider is set as follows.
input_slider:
dsp1hp_cyan:
name: "cyan ink"
initial: 0
min: 0
max: 100
step: 1
Here is the error.
2017-05-08 11:31:37.084124 WARNING ------------------------------------------------------------
2017-05-08 11:34:17.420535 WARNING ------------------------------------------------------------
2017-05-08 11:34:17.421273 WARNING Unexpected error during loading of printermonitor:
2017-05-08 11:34:17.421795 WARNING ------------------------------------------------------------
2017-05-08 11:34:17.423438 WARNING Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/appdaemon/appdaemon.py", line 996, in read_app
init_object(name, class_name, module_name, config[name])
File "/usr/local/lib/python3.4/dist-packages/appdaemon/appdaemon.py", line 690, in init_object
conf.objects[name]["object"].initialize()
File "/home/homeassistant/code/appdaemon/printermonitor/printermonitor.py", line 62, in initialize
self.check_printers()
File "/home/homeassistant/code/appdaemon/printermonitor/printermonitor.py", line 131, in check_printers
self.set_state("input_slider."+printername+"_"+markername,state=markerpctfull)
File "/usr/local/lib/python3.4/dist-packages/appdaemon/appapi.py", line 206, in set_state
r.raise_for_status()
File "/usr/local/lib/python3.4/dist-packages/requests/models.py", line 909, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http://localhost:8123/api/states/input_slider.dsp1hp_cyan
Here is the section of code in question:
markerpctfull=int((markercurrent/markercapacity)*100)
if markerpctfull < 10: # < 10% marker means we are low on something
low=True
self.log("{} is {:0.2f}% full".format(markername,
(markercurrent/markercapacity)*100))
self.log("markerpctfull={}".format(markerpctfull))
# set values for input_sliders
self.set_state("input_slider."+printername+"_"+markername,state=markerpctfull)
if I change the set state line as follows
self.set_state("input_slider."+printername+"_"+markername,state=markerpctfull if markerpctfull >0 else 1)
everything works fine.
Considering it’s the integer representation of a percentage I’m displaying, it’s not a big deal (0 vs1%) but it is annoying. Is it that the value I’m trying to display is “0” or because it’s equal to the min value?