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
a0584a05
Unverified
Commit
a0584a05
authored
3 months ago
by
Robert Resch
Committed by
GitHub
3 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Remove deprecated switch constants (#131806)
* Remove deprecated switch constants * Fix
parent
96dfa0e0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
homeassistant/components/switch/__init__.py
+1
-24
1 addition, 24 deletions
homeassistant/components/switch/__init__.py
tests/components/switch/test_init.py
+1
-22
1 addition, 22 deletions
tests/components/switch/test_init.py
with
2 additions
and
46 deletions
homeassistant/components/switch/__init__.py
+
1
−
24
View file @
a0584a05
...
...
@@ -4,7 +4,6 @@ from __future__ import annotations
from
datetime
import
timedelta
from
enum
import
StrEnum
from
functools
import
partial
import
logging
from
propcache
import
cached_property
...
...
@@ -19,12 +18,6 @@ from homeassistant.const import (
)
from
homeassistant.core
import
HomeAssistant
from
homeassistant.helpers
import
config_validation
as
cv
from
homeassistant.helpers.deprecation
import
(
DeprecatedConstantEnum
,
all_with_deprecated_constants
,
check_if_deprecated_constant
,
dir_with_deprecated_constants
,
)
from
homeassistant.helpers.entity
import
ToggleEntity
,
ToggleEntityDescription
from
homeassistant.helpers.entity_component
import
EntityComponent
from
homeassistant.helpers.typing
import
ConfigType
...
...
@@ -52,16 +45,8 @@ class SwitchDeviceClass(StrEnum):
DEVICE_CLASSES_SCHEMA
=
vol
.
All
(
vol
.
Lower
,
vol
.
Coerce
(
SwitchDeviceClass
))
# DEVICE_CLASS* below are deprecated as of 2021.12
# use the SwitchDeviceClass enum instead.
DEVICE_CLASSES
=
[
cls
.
value
for
cls
in
SwitchDeviceClass
]
_DEPRECATED_DEVICE_CLASS_OUTLET
=
DeprecatedConstantEnum
(
SwitchDeviceClass
.
OUTLET
,
"
2025.1
"
)
_DEPRECATED_DEVICE_CLASS_SWITCH
=
DeprecatedConstantEnum
(
SwitchDeviceClass
.
SWITCH
,
"
2025.1
"
)
# mypy: disallow-any-generics
...
...
@@ -124,11 +109,3 @@ class SwitchEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_)
if
hasattr
(
self
,
"
entity_description
"
):
return
self
.
entity_description
.
device_class
return
None
# These can be removed if no deprecated constant are in this module anymore
__getattr__
=
partial
(
check_if_deprecated_constant
,
module_globals
=
globals
())
__dir__
=
partial
(
dir_with_deprecated_constants
,
module_globals_keys
=
[
*
globals
().
keys
()]
)
__all__
=
all_with_deprecated_constants
(
globals
())
This diff is collapsed.
Click to expand it.
tests/components/switch/test_init.py
+
1
−
22
View file @
a0584a05
...
...
@@ -11,12 +11,7 @@ from homeassistant.setup import async_setup_component
from
.
import
common
from
.common
import
MockSwitch
from
tests.common
import
(
MockUser
,
help_test_all
,
import_and_test_deprecated_constant_enum
,
setup_test_component_platform
,
)
from
tests.common
import
MockUser
,
setup_test_component_platform
@pytest.fixture
(
autouse
=
True
)
...
...
@@ -87,19 +82,3 @@ async def test_switch_context(
assert
state2
is
not
None
assert
state
.
state
!=
state2
.
state
assert
state2
.
context
.
user_id
==
hass_admin_user
.
id
def
test_all
()
->
None
:
"""
Test module.__all__ is correctly set.
"""
help_test_all
(
switch
)
@pytest.mark.parametrize
((
"
enum
"
),
list
(
switch
.
SwitchDeviceClass
))
def
test_deprecated_constants
(
caplog
:
pytest
.
LogCaptureFixture
,
enum
:
switch
.
SwitchDeviceClass
,
)
->
None
:
"""
Test deprecated constants.
"""
import_and_test_deprecated_constant_enum
(
caplog
,
switch
,
enum
,
"
DEVICE_CLASS_
"
,
"
2025.1
"
)
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