Skip to content

Commit c071fe0

Browse files
committed
fix(time): Catch invalid time format
1 parent dae8437 commit c071fe0

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

custom_components/nodered/time.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
async def async_setup_entry(hass, config_entry, async_add_entities):
27-
"""Set up the number platform."""
27+
"""Set up the time platform."""
2828

2929
async def async_discover(config, connection):
3030
await _async_setup_entity(hass, config, async_add_entities, connection)
@@ -37,27 +37,31 @@ async def async_discover(config, connection):
3737

3838

3939
async def _async_setup_entity(hass, config, async_add_entities, connection):
40-
"""Set up the Node-RED number."""
40+
"""Set up the Node-RED time."""
4141

42-
async_add_entities([NodeRedNumber(hass, config, connection)])
42+
async_add_entities([NodeRedTime(hass, config, connection)])
4343

4444

4545
def _convert_string_to_time(value):
4646
"""Convert string to time."""
4747
if value is None:
4848
return None
49-
return parser.parse(value).time()
49+
try:
50+
return parser.parse(value).time()
51+
except ValueError:
52+
_LOGGER.error(f"Unable to parse time: {value}")
53+
return None
5054

5155

52-
class NodeRedNumber(NodeRedEntity, TimeEntity):
53-
"""Node-RED number class."""
56+
class NodeRedTime(NodeRedEntity, TimeEntity):
57+
"""Node-RED time class."""
5458

5559
_attr_native_value = None
5660
_bidirectional = True
5761
_component = CONF_TIME
5862

5963
def __init__(self, hass, config, connection):
60-
"""Initialize the number."""
64+
"""Initialize the time."""
6165
super().__init__(hass, config)
6266
self._message_id = config[CONF_ID]
6367
self._connection = connection

0 commit comments

Comments
 (0)