Optional section at start of obis code

This commit is contained in:
Jesse Hills 2022-09-16 12:04:30 +12:00
parent 7a91ca9809
commit c2df7a9d55
No known key found for this signature in database
GPG key ID: BEAAE804EFD8E83A

View file

@ -32,7 +32,7 @@ async def to_code(config):
def obis_code(value):
value = cv.string(value)
match = re.match(r"^\d{1,3}-\d{1,3}:\d{1,3}\.\d{1,3}\.\d{1,3}$", value)
match = re.match(r"^(?:\d{1,3}-\d{1,3}:)?\d{1,3}\.\d{1,3}\.\d{1,3}$", value)
if match is None:
raise cv.Invalid(f"{value} is not a valid OBIS code")
return value