Grizzly.ZIPGateway.Database (grizzly v8.14.0)
View SourceFunctions for inspecting and debugging Z/IP Gateway's SQLite database.
Summary
Functions
Returns a list of all nodes.
Decodes the bitmask stored in the nodes.mode
field into a keyword list.
Decodes the bitmask stored in the nodes.state
field into an atom.
Decodes the bitmask stored in the nodes.probe_flags
field into an atom.
Decodes the bitmask stored in the nodes.properties_flags
field into a keyword list.
Decodes the bitmask stored in the nodes.security_flags
field into a keyword list.
Decodes a node's Version CC capabilities bitmask stored in the
nodes.node_version_cap_and_zwave_sw
field into a keyword list.
Deletes a node (and its endpoints) from the database. The DSK field will be permanently lost, but that's probably not a major issue.
Execute a query that doesn't return any rows. It is an error to use a select statement with this function.
Returns a list of nodes that have don't have any entries in the endpoints table.
Looks up a endpoint by node id and endpoint id and returns a map or nil if not found. Returns endpoint 0 (the root device) if no endpoint_id is specified.
Looks up a node by its ID and returns a map or nil if not found.
Returns a list of the given node's endpoints.
Prepares and executes the given query. Returns a list of maps, where map keys are column names and values are the corresponding row values.
Same as select_all/3
, but returns only the first row or nil.
Same as with_database/2
, but uses the database file pointed to by Grizzly.options/0
.
Opens a SQLite database and passes the connection handle to the given function, then closes the database on completion.
Types
@type node_mode() ::
:not_probed
| :nonlistening
| :always_listening
| :flirs
| :wakeup
| :wakeup_firmware_upgrade
@type node_state() ::
:created
| :probe_node_info
| :probe_product_id
| :enumerate_endpoints
| :find_endpoints
| :check_wakeup_cc_version
| :get_wakeup_capabilities
| :set_wakeup_interval
| :assign_return_route
| :probe_wakeup_interval
| :probe_endpoints
| :mdns_probe
| :mdns_endpoint_probe
| :done
| :probe_fail
| :failing
@type probe_state() :: :ok | :never_started | :probe_started | :probe_failed
@type query_result(result) :: {:ok, result} | {:error, Exqlite.Sqlite3.reason()}
@type security_flag() :: {:s0 | :s2_unauthenticated | :s2_authenticated | :s2_access_control | :known_bad, boolean()}
@type version_capability() ::
:version_get | :version_command_class_get | :version_zwave_software_get
@type zwave_node() :: %{ id: Grizzly.zwave_node_id(), dsk: Grizzly.ZWave.DSK.t() | nil, last_awake: pos_integer(), last_update: pos_integer(), manufacturer_id: 0..65535, product_type: 0..65535, product_id: 0..65535, mode: [mode_flag()], security_flags: [security_flag()], properties_flags: [properties_flag()], probe_state: probe_state(), state: node_state(), version_capabilities: [{version_capability(), boolean()}], basic_device_class: Grizzly.ZWave.DeviceClasses.basic_device_class() | nil, wake_up_interval: non_neg_integer() | nil }
Functions
@spec all_nodes(Exqlite.Sqlite3.db()) :: query_result([map()])
Returns a list of all nodes.
Decodes the bitmask stored in the nodes.mode
field into a keyword list.
@spec decode_node_state(integer()) :: node_state() | :unknown
Decodes the bitmask stored in the nodes.state
field into an atom.
@spec decode_probe_state(integer()) :: probe_state() | :unknown
Decodes the bitmask stored in the nodes.probe_flags
field into an atom.
@spec decode_properties_flags(integer()) :: [properties_flag()]
Decodes the bitmask stored in the nodes.properties_flags
field into a keyword list.
@spec decode_security_flags(integer()) :: [security_flag()]
Decodes the bitmask stored in the nodes.security_flags
field into a keyword list.
@spec decode_version_capabilities(integer()) :: [{version_capability(), boolean()}]
Decodes a node's Version CC capabilities bitmask stored in the
nodes.node_version_cap_and_zwave_sw
field into a keyword list.
@spec delete_node(Exqlite.Sqlite3.db(), integer()) :: :ok | {:error, Exqlite.Sqlite3.reason()}
Deletes a node (and its endpoints) from the database. The DSK field will be permanently lost, but that's probably not a major issue.
@spec execute(Exqlite.Sqlite3.db(), binary(), list()) :: :ok | {:error, Exqlite.Sqlite3.reason()}
Execute a query that doesn't return any rows. It is an error to use a select statement with this function.
@spec find_nodes_with_no_endpoints(Exqlite.Sqlite3.db()) :: query_result([map()])
Returns a list of nodes that have don't have any entries in the endpoints table.
@spec get_endpoint(Exqlite.Sqlite3.db(), pos_integer(), non_neg_integer()) :: query_result(map() | nil)
Looks up a endpoint by node id and endpoint id and returns a map or nil if not found. Returns endpoint 0 (the root device) if no endpoint_id is specified.
@spec get_node(Exqlite.Sqlite3.db(), integer()) :: query_result(map() | nil)
Looks up a node by its ID and returns a map or nil if not found.
@spec get_node_endpoints(Exqlite.Sqlite3.db(), integer()) :: query_result([map()])
Returns a list of the given node's endpoints.
@spec select_all(Exqlite.Sqlite3.db(), binary(), list()) :: query_result([map()])
Prepares and executes the given query. Returns a list of maps, where map keys are column names and values are the corresponding row values.
@spec select_one(Exqlite.Sqlite3.db(), binary(), list()) :: query_result(map() | nil)
Same as select_all/3
, but returns only the first row or nil.
@spec with_database((Exqlite.Sqlite3.db() -> any())) :: any()
Same as with_database/2
, but uses the database file pointed to by Grizzly.options/0
.
@spec with_database(Path.t() | reference(), (Exqlite.Sqlite3.db() -> any())) :: any()
Opens a SQLite database and passes the connection handle to the given function, then closes the database on completion.
If the first argument is a reference to an already-open SQLite database, the first and last steps will be skipped. This is mostly useful for testing.
If the given database file does not exist, an error will be returned. Otherwise, the return value will be the result of the given function.
Z/IP Gateway should be stopped prior to making any modifications to the database, otherwise it will ignore and most likely overwrite your changes. This function will return an error if Z/IP Gateway is running and the first argument. If you want to bypass this check, open the database and pass the connection handle.
@spec with_statement(Exqlite.Sqlite3.db(), binary(), (Exqlite.Sqlite3.statement() -> result)) :: result when result: var