Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try fix IndexError: list index out of range #5

Merged
merged 2 commits into from
Jan 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions custom_components/novus300bus/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
from homeassistant.components.binary_sensor import (DEVICE_CLASS_PLUG,
BinarySensorEntity)
from homeassistant.components.binary_sensor import BinarySensorDeviceClass, BinarySensorEntity
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import (CONF_NAME, DEVICE_CLASS_TEMPERATURE,
TEMP_CELSIUS)
from homeassistant.const import CONF_NAME, TEMP_CELSIUS
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.util import Throttle
from homeassistant.components.sensor import SensorDeviceClass
from serial import EIGHTBITS, PARITY_MARK, STOPBITS_ONE, Serial

# endregion Imports
Expand Down Expand Up @@ -147,7 +146,7 @@ def consumePackage(data, recursion=0):
# try:
while not isCommand(data[2]):
data = data[1:]
if len(data) < 2:
if len(data) < 3:
break
if data[2] != Command.OTHER.value:
if isCommand(data[2]):
Expand Down Expand Up @@ -366,7 +365,7 @@ def __init__(self, hass, id, friendly_name):
self._name = friendly_name
self._attr_icon = 'mdi:compare-horizontal'
self._is_on = None
self._attr_device_class = DEVICE_CLASS_PLUG
self._attr_device_class = BinarySensorDeviceClass.PLUG

@property
def name(self):
Expand All @@ -389,7 +388,7 @@ def __init__(self, hass, id, friendly_name):
self._name = friendly_name
self._state = None
# self._attr_icon = icon
# self._attr_device_class = DEVICE_CLASS_TEMPERATURE
# self._attr_device_class = SensorDeviceClass.TEMPERATURE
# self._attr_unit_of_measurement = TEMP_CELSIUS

@property
Expand Down Expand Up @@ -417,5 +416,5 @@ def __init__(self, hass, id, friendly_name, icon='hass:thermometer'):
self._attr_icon = icon
self._state = None
# self._attr_should_poll = True # self._port is not None
self._attr_device_class = DEVICE_CLASS_TEMPERATURE
self._attr_device_class = SensorDeviceClass.TEMPERATURE
self._attr_unit_of_measurement = TEMP_CELSIUS