Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """Support for controlling Global Cache gc100."""
2 
3 import gc100
4 import voluptuous as vol
5 
6 from homeassistant.const import CONF_HOST, CONF_PORT, EVENT_HOMEASSISTANT_STOP
7 from homeassistant.core import HomeAssistant
9 from homeassistant.helpers.typing import ConfigType
10 
11 CONF_PORTS = "ports"
12 
13 DEFAULT_PORT = 4998
14 DOMAIN = "gc100"
15 
16 DATA_GC100 = "gc100"
17 
18 CONFIG_SCHEMA = vol.Schema(
19  {
20  DOMAIN: vol.Schema(
21  {
22  vol.Required(CONF_HOST): cv.string,
23  vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
24  }
25  )
26  },
27  extra=vol.ALLOW_EXTRA,
28 )
29 
30 
31 def setup(hass: HomeAssistant, base_config: ConfigType) -> bool:
32  """Set up the gc100 component."""
33  config = base_config[DOMAIN]
34  host = config[CONF_HOST]
35  port = config[CONF_PORT]
36 
37  gc_device = gc100.GC100SocketClient(host, port)
38 
39  def cleanup_gc100(event):
40  """Stuff to do before stopping."""
41  gc_device.quit()
42 
43  hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, cleanup_gc100)
44 
45  hass.data[DATA_GC100] = GC100Device(hass, gc_device)
46 
47  return True
48 
49 
51  """The GC100 component."""
52 
53  def __init__(self, hass, gc_device):
54  """Init a gc100 device."""
55  self.hasshass = hass
56  self.gc_devicegc_device = gc_device
57 
58  def read_sensor(self, port_addr, callback):
59  """Read a value from a digital input."""
60  self.gc_devicegc_device.read_sensor(port_addr, callback)
61 
62  def write_switch(self, port_addr, state, callback):
63  """Write a value to a relay."""
64  self.gc_devicegc_device.write_switch(port_addr, state, callback)
65 
66  def subscribe(self, port_addr, callback):
67  """Add detection for RISING and FALLING events."""
68  self.gc_devicegc_device.subscribe_notify(port_addr, callback)
def __init__(self, hass, gc_device)
Definition: __init__.py:53
def write_switch(self, port_addr, state, callback)
Definition: __init__.py:62
def read_sensor(self, port_addr, callback)
Definition: __init__.py:58
def subscribe(self, port_addr, callback)
Definition: __init__.py:66
bool setup(HomeAssistant hass, ConfigType base_config)
Definition: __init__.py:31