Implement more efficient is_dev_attrib_enabled()

This commit is contained in:
Paul Gear 2015-06-13 09:26:26 +10:00
parent 78bf0b7a0a
commit 982faeb869

View File

@ -453,16 +453,6 @@ function get_dev_attribs($device)
return $attribs;
}
function is_dev_attrib_enabled($device, $attrib)
{
foreach (get_dev_attribs($device) as $name => $val) {
if ($name == $attrib && $val == 0) {
return false;
}
}
return true;
}
function get_dev_entity_state($device)
{
$state = array();
@ -486,6 +476,19 @@ function get_dev_attrib($device, $attrib_type)
}
}
function is_dev_attrib_enabled($device, $attrib, $default = true)
{
$val = get_dev_attrib($device, $attrib);
if ($val != NULL) {
// attribute is set
return ($val != 0);
}
else {
// attribute not set
return $default;
}
}
function del_dev_attrib($device, $attrib_type)
{
return dbDelete('devices_attribs', "`device_id` = ? AND `attrib_type` = ?", array($device['device_id'], $attrib_type));