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
25f15c11
Unverified
Commit
25f15c11
authored
2 weeks ago
by
epenet
Committed by
GitHub
2 weeks ago
Browse files
Options
Downloads
Patches
Plain Diff
Use short-hand attributes in remote-rpi-gpio (#140263)
parent
e831b1b2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
homeassistant/components/remote_rpi_gpio/binary_sensor.py
+8
-15
8 additions, 15 deletions
homeassistant/components/remote_rpi_gpio/binary_sensor.py
homeassistant/components/remote_rpi_gpio/switch.py
+7
-20
7 additions, 20 deletions
homeassistant/components/remote_rpi_gpio/switch.py
with
15 additions
and
35 deletions
homeassistant/components/remote_rpi_gpio/binary_sensor.py
+
8
−
15
View file @
25f15c11
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
from
__future__
import
annotations
from
__future__
import
annotations
from
gpiozero
import
DigitalInputDevice
import
requests
import
requests
import
voluptuous
as
vol
import
voluptuous
as
vol
...
@@ -48,10 +49,10 @@ def setup_platform(
...
@@ -48,10 +49,10 @@ def setup_platform(
discovery_info
:
DiscoveryInfoType
|
None
=
None
,
discovery_info
:
DiscoveryInfoType
|
None
=
None
,
)
->
None
:
)
->
None
:
"""
Set up the Raspberry PI GPIO devices.
"""
"""
Set up the Raspberry PI GPIO devices.
"""
address
=
config
[
"
host
"
]
address
=
config
[
CONF_HOST
]
invert_logic
=
config
[
CONF_INVERT_LOGIC
]
invert_logic
=
config
[
CONF_INVERT_LOGIC
]
pull_mode
=
config
[
CONF_PULL_MODE
]
pull_mode
=
config
[
CONF_PULL_MODE
]
ports
=
config
[
"
ports
"
]
ports
=
config
[
CONF_PORTS
]
bouncetime
=
config
[
CONF_BOUNCETIME
]
/
1000
bouncetime
=
config
[
CONF_BOUNCETIME
]
/
1000
devices
=
[]
devices
=
[]
...
@@ -71,9 +72,11 @@ class RemoteRPiGPIOBinarySensor(BinarySensorEntity):
...
@@ -71,9 +72,11 @@ class RemoteRPiGPIOBinarySensor(BinarySensorEntity):
_attr_should_poll
=
False
_attr_should_poll
=
False
def
__init__
(
self
,
name
,
sensor
,
invert_logic
):
def
__init__
(
self
,
name
:
str
|
None
,
sensor
:
DigitalInputDevice
,
invert_logic
:
bool
)
->
None
:
"""
Initialize the RPi binary sensor.
"""
"""
Initialize the RPi binary sensor.
"""
self
.
_name
=
name
self
.
_
attr_
name
=
name
self
.
_invert_logic
=
invert_logic
self
.
_invert_logic
=
invert_logic
self
.
_state
=
False
self
.
_state
=
False
self
.
_sensor
=
sensor
self
.
_sensor
=
sensor
...
@@ -90,20 +93,10 @@ class RemoteRPiGPIOBinarySensor(BinarySensorEntity):
...
@@ -90,20 +93,10 @@ class RemoteRPiGPIOBinarySensor(BinarySensorEntity):
self
.
_sensor
.
when_activated
=
read_gpio
self
.
_sensor
.
when_activated
=
read_gpio
@property
@property
def
name
(
self
):
def
is_on
(
self
)
->
bool
:
"""
Return the name of the sensor.
"""
return
self
.
_name
@property
def
is_on
(
self
):
"""
Return the state of the entity.
"""
"""
Return the state of the entity.
"""
return
self
.
_state
!=
self
.
_invert_logic
return
self
.
_state
!=
self
.
_invert_logic
@property
def
device_class
(
self
):
"""
Return the class of this sensor, from DEVICE_CLASSES.
"""
return
def
update
(
self
)
->
None
:
def
update
(
self
)
->
None
:
"""
Update the GPIO state.
"""
"""
Update the GPIO state.
"""
try
:
try
:
...
...
This diff is collapsed.
Click to expand it.
homeassistant/components/remote_rpi_gpio/switch.py
+
7
−
20
View file @
25f15c11
...
@@ -4,6 +4,7 @@ from __future__ import annotations
...
@@ -4,6 +4,7 @@ from __future__ import annotations
from
typing
import
Any
from
typing
import
Any
from
gpiozero
import
LED
import
voluptuous
as
vol
import
voluptuous
as
vol
from
homeassistant.components.switch
import
(
from
homeassistant.components.switch
import
(
...
@@ -57,37 +58,23 @@ def setup_platform(
...
@@ -57,37 +58,23 @@ def setup_platform(
class
RemoteRPiGPIOSwitch
(
SwitchEntity
):
class
RemoteRPiGPIOSwitch
(
SwitchEntity
):
"""
Representation of a Remote Raspberry Pi GPIO.
"""
"""
Representation of a Remote Raspberry Pi GPIO.
"""
_attr_assumed_state
=
True
_attr_should_poll
=
False
_attr_should_poll
=
False
def
__init__
(
self
,
name
,
led
)
:
def
__init__
(
self
,
name
:
str
|
None
,
led
:
LED
)
->
None
:
"""
Initialize the pin.
"""
"""
Initialize the pin.
"""
self
.
_name
=
name
or
DEVICE_DEFAULT_NAME
self
.
_
attr_
name
=
name
or
DEVICE_DEFAULT_NAME
self
.
_
state
=
False
self
.
_
attr_is_on
=
False
self
.
_switch
=
led
self
.
_switch
=
led
@property
def
name
(
self
):
"""
Return the name of the switch.
"""
return
self
.
_name
@property
def
assumed_state
(
self
):
"""
If unable to access real state of the entity.
"""
return
True
@property
def
is_on
(
self
):
"""
Return true if device is on.
"""
return
self
.
_state
def
turn_on
(
self
,
**
kwargs
:
Any
)
->
None
:
def
turn_on
(
self
,
**
kwargs
:
Any
)
->
None
:
"""
Turn the device on.
"""
"""
Turn the device on.
"""
write_output
(
self
.
_switch
,
1
)
write_output
(
self
.
_switch
,
1
)
self
.
_
state
=
True
self
.
_
attr_is_on
=
True
self
.
schedule_update_ha_state
()
self
.
schedule_update_ha_state
()
def
turn_off
(
self
,
**
kwargs
:
Any
)
->
None
:
def
turn_off
(
self
,
**
kwargs
:
Any
)
->
None
:
"""
Turn the device off.
"""
"""
Turn the device off.
"""
write_output
(
self
.
_switch
,
0
)
write_output
(
self
.
_switch
,
0
)
self
.
_
state
=
False
self
.
_
attr_is_on
=
False
self
.
schedule_update_ha_state
()
self
.
schedule_update_ha_state
()
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