Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
904bf449
Commit
904bf449
authored
10 years ago
by
Paulus Schoutsen
Browse files
Options
Downloads
Patches
Plain Diff
Added entity_id validation to the State class
parent
f9fbb30f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
homeassistant/__init__.py
+13
-0
13 additions, 0 deletions
homeassistant/__init__.py
with
13 additions
and
0 deletions
homeassistant/__init__.py
+
13
−
0
View file @
904bf449
...
...
@@ -12,6 +12,7 @@ import time
import
logging
import
threading
import
enum
import
re
import
datetime
as
dt
import
functools
as
ft
...
...
@@ -46,6 +47,9 @@ TIMER_INTERVAL = 10 # seconds
# Number of worker threads
POOL_NUM_THREAD
=
4
# Pattern for validating entity IDs (format: <domain>.<entity>)
ENTITY_ID_PATTERN
=
re
.
compile
(
r
"
^(?P<domain>\w+)\.(?P<entity>\w+)$
"
)
class
HomeAssistant
(
object
):
"""
Core class to route all communication to right components.
"""
...
...
@@ -399,6 +403,11 @@ class State(object):
__slots__
=
[
'
entity_id
'
,
'
state
'
,
'
attributes
'
,
'
last_changed
'
]
def
__init__
(
self
,
entity_id
,
state
,
attributes
=
None
,
last_changed
=
None
):
if
not
ENTITY_ID_PATTERN
.
match
(
entity_id
):
raise
InvalidEntityFormatError
((
"
Invalid entity id encountered: {}.
"
"
Format should be <domain>.<entity>
"
).
format
(
entity_id
))
self
.
entity_id
=
entity_id
self
.
state
=
state
self
.
attributes
=
attributes
or
{}
...
...
@@ -641,3 +650,7 @@ class Timer(threading.Thread):
class
HomeAssistantError
(
Exception
):
"""
General Home Assistant exception occured.
"""
class
InvalidEntityFormatError
(
HomeAssistantError
):
"""
When an invalid formatted entity is encountered.
"""
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment